#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) void init () { std::istringstream setstrm ("[Sinks.TextFileSettings]\n" \ "Destination=Console\n" \ "Format=\"parse: %LineID%: <%Severity%> %Message%\"\n"); logging::init_from_settings(logging::parse_settings(setstrm)); logging::add_console_log( std::clog, keywords::format = ( expr::stream << "const: " << line_id << ": <" << severity << "> " << expr::smessage ) ); } int main (int, char*[]) { init(); src::severity_logger< severity_level > lg; BOOST_LOG_SEV(lg, normal) << "normal 1"; BOOST_LOG_SEV(lg, critical) << "criticial 2"; return 0; }