#include #include #include #include #include #include #include #include #include namespace logging = boost::log; namespace src = boost::log::sources; namespace expr = boost::log::expressions; namespace keywords = boost::log::keywords; #if 1 // use normal enum enum severity_level { normal, critical }; #else // simulate with typedef and #defs typedef unsigned int severity_level; #define normal 0 #define critical 1 #endif std::ostream& operator<< (std::ostream& strm, severity_level level) { std::cerr << __FILE__ << ":" << __LINE__ << ": operator<<(" << strm << ", " << static_cast< std::size_t >(level) << ")\n"; static const char* strings[] = { "normal", "critical" }; if (static_cast< std::size_t >(level) < 2) strm << strings[level]; else strm << static_cast< int >(level); return strm; } BOOST_LOG_ATTRIBUTE_KEYWORD(line_id, "LineID", unsigned int) BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level) BOOST_LOG_ATTRIBUTE_KEYWORD(channel, "Channel", std::string) void init () { std::istringstream setstrm ("[Sinks.TextFileSettings]\n" \ "Destination=Console\n" \ "Format=\"parse: %LineID%: <%Severity%> [%Channel%] %Message%\"\n"); logging::init_from_settings(logging::parse_settings(setstrm)); logging::add_console_log( std::clog, keywords::format = ( expr::stream << "const: " << line_id << ": <" << severity << "> [" << channel << "] " << expr::smessage ) ); } int main (int, char*[]) { init(); src::severity_channel_logger< severity_level, std::string > lg; BOOST_LOG_CHANNEL_SEV(lg, "channel 1", normal) << "normal channel 1"; BOOST_LOG_CHANNEL_SEV(lg, "channel 2", critical) << "criticial channel 2"; return 0; }