id summary reporter owner description type status milestone component version severity resolution keywords cc 10238 syslog pri part error in custom severity (init_from_stream) anonymous Andrey Semashev "Hi all, I'm trying to tune logging from settings to be able to send message to Syslog, TextFile and Console. I use %Severity% keyword in all these cases. My task is get text value of severity in TextFile and Console, and to get correct format of message in Syslog. During executing the code below I've got an error pri part in SyslogViewer [ #TextFile - OK [2014-Jul-24 10:27:28.611879] This is a debug severity record [2014-Jul-24 10:27:28.627501] This is a info severity record [2014-Jul-24 10:27:28.658746] This is a warning severity record [2014-Jul-24 10:27:28.674369] This is a error severity record [2014-Jul-24 10:27:28.705613] This is a critical severity record #Syslog - ERROR PRI PART <14> Jul 24 10:27:28 10.10.10.73 test.exe This is a debug severity record <14> Jul 24 10:27:28 10.10.10.73 test.exe This is a info severity record <14> Jul 24 10:27:28 10.10.10.73 test.exe This is a warning severity record <14> Jul 24 10:27:28 10.10.10.73 test.exe This is a error severity record <14> Jul 24 10:27:28 10.10.10.73 test.exe This is a critical severity record ] Every record has Syslog pri part equals to <14>. That is mistake! P.S. If I use int instead of enum as severity level, everything is ok in Syslog, but in this case I can not get text values of %Severity% in TextFile and Console [ #TextFile - I need %Severity% as text here <15>[2014-Jul-24 10:27:28.611879] This is a debug severity record <14>[2014-Jul-24 10:27:28.627501] This is a info severity record <12>[2014-Jul-24 10:27:28.658746] This is a warning severity record <11>[2014-Jul-24 10:27:28.674369] This is a error severity record <10>[2014-Jul-24 10:27:28.705613] This is a critical severity record #Syslog <15> Jul 24 10:44:16 MaZhorWork fmod_test.exe This is a debug severity record <14> Jul 24 10:44:16 MaZhorWork fmod_test.exe This is a info severity record <12> Jul 24 10:44:17 MaZhorWork fmod_test.exe This is a warning severity record <11> Jul 24 10:44:17 MaZhorWork fmod_test.exe This is a error severity record <10> Jul 24 10:44:17 MaZhorWork fmod_test.exe This is a critical severity record ] P.S.2. In my opinion problem is in $(BOOST_ROOT_55)\libs\log\src\init_from_settings.cpp, line 453: {{{ // For now we use only the default level mapping. Will add support for configuration later. backend->set_severity_mapper(sinks::syslog::direct_severity_mapping< >(log::aux::default_attribute_names::severity())); }}} My code that I tried {{{ //Here we define our application severity levels. typedef enum TSysLogSeverity { slEmergency = boost::log::sinks::syslog::emergency, slAlert = boost::log::sinks::syslog::alert, slCritical = boost::log::sinks::syslog::critical, slError = boost::log::sinks::syslog::error, slWarning = boost::log::sinks::syslog::warning, slNotice = boost::log::sinks::syslog::notice, slInfo = boost::log::sinks::syslog::info, slDebug = boost::log::sinks::syslog::debug }; // The operator is used for regular stream formatting std::ostream& operator<< (std::ostream& strm, TSysLogSeverity level) { static const char* strings[] = { ""EMERGENCY"", ""ALERT"", ""CRITICAL"", ""ERROR"", ""WARNING"", ""NOTICE"", ""INFO"", ""DEBUG"" }; if (static_cast< std::size_t >(level) < sizeof(strings) / sizeof(*strings)) strm << strings[level]; else strm << level; return strm; } std::istream& operator>>(std::istream& i, TSysLogSeverity &level) { std::string s_tmp; i >> s_tmp; static const char* strings[] = { ""EMERGENCY"", ""ALERT"", ""CRITICAL"", ""ERROR"", ""WARNING"", ""NOTICE"", ""INFO"", ""DEBUG"" }; bool bFound = false; const std::size_t i_array_size = sizeof(strings) / sizeof(*strings); for (int k = 0; k < i_array_size ; k++) { if (s_tmp == std::string(strings[k])) { level = TSysLogSeverity(k); bFound = true; break; } } if (!bFound) { level = TSysLogSeverity(std::stoul(s_tmp)); } return i; } // Attribute value tag type struct severity_tag; // The operator is used when putting the severity level to log boost::log::formatting_ostream& operator<< ( boost::log::formatting_ostream& strm, boost::log::to_log_manip< TSysLogSeverity, severity_tag > const& manip ) { static const char* strings[] = { ""EMERGENCY"", ""ALERT"", ""CRITICAL"", ""ERROR"", ""WARNING"", ""NOTICE"", ""INFO"", ""DEBUG"" }; TSysLogSeverity level = manip.get(); if (static_cast< std::size_t >(level) < sizeof(strings) / sizeof(*strings)) strm << strings[level]; else strm << static_cast< int >(level); return strm; } // Global logger declaration BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(test_lg, src::severity_logger_mt) void try_logging() { src::severity_logger_mt& lg = test_lg::get(); BOOST_LOG_SEV(lg, slDebug) << ""This is a debug severity record""; BOOST_LOG_SEV(lg, slInfo) << ""This is a info severity record""; BOOST_LOG_SEV(lg, slWarning) << ""This is a warning severity record""; BOOST_LOG_SEV(lg, slError) << ""This is a error severity record""; BOOST_LOG_SEV(lg, slCritical) << ""This is a critical severity record""; } int _tmain(int argc, _TCHAR* argv[]) { try { boost::filesystem::path p(argv[0]); p = p.replace_extension("".ini""); // Open the file std::ifstream settings(p.string()); if (!settings.is_open()) { throw std::runtime_error(""Could not open <"" + p.string() + ""> file""); } boost::log::register_simple_formatter_factory(boost::log::aux::default_attribute_names::severity()); boost::log::register_simple_filter_factory(boost::log::aux::default_attribute_names::severity()); // Read the settings and initialize logging library logging::init_from_stream(settings); src::severity_logger_mt& lg = test_lg::get(); // Add some attributes logging::add_common_attributes(); // Try logging try_logging(); } catch (std::exception& e) { std::cout << ""FAILURE: "" << e.what() << std::endl; } _getch(); return 0; } }}}" Bugs closed To Be Determined log Boost 1.55.0 Problem fixed