Opened 7 years ago

Closed 7 years ago

#11720 closed Support Requests (fixed)

Problem with 2 loggers in one class

Reported by: parikshit.nangre@… Owned by: Andrey Semashev
Milestone: To Be Determined Component: log
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

Hello,

i am using src::severity_logger< severity_level > and facing some issue. Here is the issue and code -

I have 2 loggers in a class as class members

class A { src::severity_logger< severity_level > m_DbLogger; src::severity_logger< severity_level > m_DiagnosticsLogger;

}

i want to use 2 loggers, m_DbLogger for logs related to stored procedures and m_DiagnosticsLogger to log if any error occured while executing some stored procedure.

i am usign following code -

logging::add_file_log (

keywords::auto_flush = true, keywords::file_name = mylogfile + ".log", keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), keywords::format = (

boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << ": [" << boost::log::expressions::attr< severity_level >("Severity") << "] " << boost::log::expressions::smessage

)

);

logging::add_file_log (

keywords::auto_flush = true, keywords::file_name = mylogfile + "_diagnostics.log", keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), keywords::format = (

boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << ": [" << boost::log::expressions::attr< severity_level >("Severity") << "] " << boost::log::expressions::smessage

)

);

i want to use mylogfile + ".log" for m_DbLogger and want to use mylogfile + "_diagnostics.log" for m_DiagnosticsLogger but when try to log with -

LOG_MAIN_INFO_EX(m_DbLogger, "/* try #" << i << " " << (ws.elapsed() / 1000) << " [ms]*/ " << statement);

where macro is defined as - #define LOG_MAIN_INFO_EX(logger, _str) BOOST_LOG_SEV(logger, info) << _str;

In this case the log goes in both file and not just in mylogfile.log but also in mylogfile_diagnostics.log file as well.

I want the log to go in just 1 file ie in mylogfile.log.

And when i call LOG_MAIN_ERROR_EX(m_DiagnosticsLogger, "Statement : " << statement); where macro is defined as - #define LOG_MAIN_ERROR_EX(logger, _str) BOOST_LOG_SEV(logger, error) << _str;

in this case i want this log to go only in mylogfile_diagnostics.log and not in mylogfile.log

Basically i want to connect following block to m_DbLogger logging::add_file_log (

keywords::auto_flush = true, keywords::file_name = mylogfile + ".log", keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), keywords::format = (

boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << ": [" << boost::log::expressions::attr< severity_level >("Severity") << "] " << boost::log::expressions::smessage

)

);

and want to connect following bloack to m_DiagnosticsLogger logging::add_file_log (

keywords::auto_flush = true, keywords::file_name = mylogfile + "_diagnostics.log", keywords::time_based_rotation = sinks::file::rotation_at_time_point(0, 0, 0), keywords::format = (

boost::log::expressions::stream << boost::log::expressions::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") << ": [" << boost::log::expressions::attr< severity_level >("Severity") << "] " << boost::log::expressions::smessage

)

);

Please update me asap. Thanks, Parikshit

Change History (1)

comment:1 by Andrey Semashev, 7 years ago

Resolution: fixed
Status: newclosed

Please, ask questions on StackOverflow. This tracker is for bug reports.

You need to use attributes (channels) and filters to achieve that. See this answer.

Note: See TracTickets for help on using tickets.