0

I had read boost doc. But what it described are too limit for my requirement:

My project has a main logger which used to log almost all logs, it use time_based_rotation. Also I want log some message into another file, so I can check those logs independently rather than mix with main logs together.

What I want is:

BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(gl, boost::log::sources::severity_logger_mt<Logger::severity_level>)
BOOST_LOG(gl::get())<<message; // the main logger

BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(loggerA, boost::log::sources::logger_mt)
BOOST_LOG(loggerA)<<message; // another logger, log to anther file

The problem is: how should I set the logging core? Add a text_multifile_backend? But the usage is totally different than boost example. I feel in my requirement the file name setting should belong to logger rather than logging core, however I don't know how to do that.

jean
  • 2,825
  • 2
  • 35
  • 72
  • See this answer: http://stackoverflow.com/questions/34362871/use-channel-hiearchy-of-boost-log-for-severity-and-sink-filtering/34372526#34372526 – Andrey Semashev Mar 16 '16 at 14:48
  • Great, I have done this. But there still a little problem, I use text_multifile_backend to log to different file according to account name. But the LineID is an global variable by "boost::log::add_common_attributes()". How to let each "account_name.log" has its own exclusive LineID? Even I add attribute for this text_multifile_backend sink still can not make that -- the LineID counter should belong to file – jean Mar 17 '16 at 10:45
  • Attributes are not related to sinks, so you can't do that unless you maintain a single logger for every file and add the LineID counter to that logger. You won't use the attribute added by `add_common_attributes` in that case, so you may as well replace that call with your code adding the needed attributes as you need. – Andrey Semashev Mar 17 '16 at 11:51

1 Answers1

0

Take a look at this page, You may get some idea.

My program doesn't support thread safe logging while using boost library

Community
  • 1
  • 1