Subject: Re: [boost] [log] init_from_settings - problem with applying format and filter
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2011-07-04 08:51:37
On 07/04/2011 03:47 PM, Petrovskiy Yuriy wrote:
> The questions are:
> - How to configure severity_logger using init_from_settings() to get the
> custom severity levels in the log?
You have to register any user-defined attribute value types with the
library in order to be able to use it with filter and format parsers.
This includes your severity level enum.
If your type supports insertion and extraction from stream, you can do
it by these two lines:
See here for more details:
> - Why "Format" variables do not work? (and why %TimeStamp% starts to work
> if using BOOST_LOG_TRIVIAL for output)?
Because you didn't add the TimeStamp attribute to the core. Your log
records don't contain time stamps and thus you don't see them in the output.
BOOST_LOG_TRIVIAL implicitly initializes the library in its own way,
adding the attribute in the process, that's why it works after using it.
However, you should not use this macro if you use other ways of
initialization (such as from settings).
> - What should be done to make logger append to log (not overwrite)?
You should specify open_mode parameter when creating the text file sink,
keywords::file_name = "my.log",
keywords::open_mode = std::ios::app);
You can also pass this option to the backend constructor, if you create
> - Is it possible to log file and line using format variables (only to file)?
You mean file and line where a log record is made? You can do this, but
only if you add file name and line number as attributes to each record.
You can wrap in the logging macros to do this automatically.