|
Boost : |
Subject: [boost] Phoenix V3 and Logging library help.
From: Fernando Pelliccioni (fpelliccioni_at_[hidden])
Date: 2011-07-04 11:04:59
Hi Thomas, all,
I am researching about logging libraries.
I had to discard Boost.Log ( from Andrey) because this library does not
support GCC 3.4.
I've seen other libraries, but none convinced me.
I'm thinking of writing a simple logging library, and to avoid the use of
macros, I decided to do something like this:
namespace prototype1
{
namespace levels
{
boost::phoenix::expression::argument<1>::type const trace = {{{}}};
boost::phoenix::expression::argument<1>::type const debug = {{{}}};
boost::phoenix::expression::argument<1>::type const info = {{{}}};
boost::phoenix::expression::argument<1>::type const warn = {{{}}};
boost::phoenix::expression::argument<1>::type const error = {{{}}};
boost::phoenix::expression::argument<1>::type const fatal = {{{}}};
} //namespace levels
struct dynamic_logger
{
template <typename Pred>
void log( Pred const & pred ) const
{
streams_type::const_iterator it = streams_.begin();
streams_type::const_iterator end = streams_.end();
for ( ; it != end; ++it )
{
pred( **it );
}
}
void add_target ( std::ostream & ostr )
{
streams_.push_back( &ostr );
}
typedef std::vector< std::ostream* > streams_type; //to improve
streams_type streams_;
};
template <typename Logger, typename Pred>
void log( Logger & logger, Pred const & pred )
{
return logger.log(pred);
}
} //namespace prototype1
int main(/*int argc, char* argv[]*/)
{
{
using namespace prototype1;
using namespace prototype1::levels;
std::ofstream outfile ("test.log");
dynamic_logger dl;
dl.add_target( std::cout );
dl.add_target( outfile );
dl.log ( info << "hello" << " world!" << std::endl );
dl.log ( warn << "hello" << " world!" << std::endl );
dl.log ( error << "hello" << " world!" << std::endl );
log( dl, info "hello" << " world!" << std::endl ); //free function
}
return 0;
}
This code is a simple prototype,
This code is a prototype should be improved.
The questions are:
1. Does PhoenixV3 (and Proto) supports GCC 3?
2. How to make the above code write the following ... ?
INFO - hello world!
WARN - hello world!
ERROR - hello world!
INFO - hello world!
Is it possible?
The key is to identify the different Levels. (see namespace
prototype1::levels)
Please, suggestions and criticisms are welcome.
Note: I do not intend to compete with Boost.Log.
Thanks and regards,
Fernando Pelliccioni.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk