|
Boost : |
Subject: [boost] [log] init_from_settings - problem with applying format and filter
From: Petrovskiy Yuriy (yuriy.petrovskiy_at_[hidden])
Date: 2011-07-04 07:47:20
I am trying to use boost::log for tracking application activity. I need
message with severity level output to console and more detailed output to
file.
I have the following code (most of it is copied from boost::log
documentation):
/* boostLogTest.cpp */
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/init/from_settings.hpp>
using namespace boost::log;
enum logMessageSeverityLevels
{
trace = 0 ,
debug = 1,
info = 2,
warning = 3,
error = 4,
fatal = 5
};
#define LOG(x) BOOST_LOG_SEV(logger, x )
typedef boost::log::sources::severity_logger< logMessageSeverityLevels >
loggerType;
loggerType logger(keywords::severity = error);
int main() {
boost::log::settings setts;
//setts["Core"]["Filter"] = "%Severity% >= 0"; //if set - no output anywhere
setts["Core"]["DisableLogging"] = false;
setts["Sink:Console"]["Destination"] = "Console";
setts["Sink:Console"]["Filter"] = "%Severity% >= 3"; // no output to console
in result
setts["Sink:Console"]["Format"] = "[%Severity%] %_%";
setts["Sink:Console"]["AutoFlush"] = true;
setts["Sink:File"]["Destination"] = "TextFile";
setts["Sink:File"]["FileName"] = "test_%3N.log";
setts["Sink:File"]["Format"] = "[%TimeStamp%] <%Severity%> %_%";
setts["Sink:File"]["AutoFlush"] = true;
boost::log::init_from_settings(setts);
LOG(info) << "!!!Hello World!!!";
LOG(warning) << "NO TimeStamp and Severity";
LOG(error) << "NO output if Filter is set ";
return 0;
}
result:
no output to console
file (test_000.log) is being rewritten on each run:
[] ** !!!Hello World!!!
[] ** NO date
[] ** NO severity
[] ** NO output if Filter is set
if I add
#include <boost/log/trivial.hpp>
and replace LOG definition with
#define LOG(x) BOOST_LOG_TRIVIAL( x )
I get also no console output but TWO! logs:
(boostLogTest.log)
1 [2011-Jul-04 12:14:06.331749] [0x73d190] [info] !!!Hello World!!!
2 [2011-Jul-04 12:14:06.338750] [0x73d190] [warning] NO TimeStamp and
Severity
3 [2011-Jul-04 12:14:06.339750] [0x73d190] [error] NO output if Filter is
set
....
( test_000.log )
[2011-Jul-04 12:14:06.331749] ** !!!Hello World!!!
[2011-Jul-04 12:14:06.338750] ** NO TimeStamp and Severity
[2011-Jul-04 12:14:06.339750] ** NO output if Filter is set
Built with:
g++ -Ipath\to\boost -O0 -g3 -Wall -c -fmessage-length=0
-osrc\boostLogTest.o ..\src\boostLogTest.cpp
g++ -Lpath\to\boost\libs -oboostLogTest.exe src\boostLogTest.o
-lboost_log-mgw45-mt-d-1_46_1 -lboost_log_setup-mgw45-mt-d-1_46_1
Environment: Windows 7 x64 / MinGW (gcc 4.5) / Eclipse
Boost version 1.46.1
Boost log from
https://boost-log.svn.sourceforge.net/svnroot/boost-log/trunk/boost-logRevision
603
Boost built with the same toolset.
The questions are:
- How to configure severity_logger using init_from_settings() to get the
custom severity levels in the log?
- Why "Format" variables do not work? (and why %TimeStamp% starts to work
if using BOOST_LOG_TRIVIAL for output)?
- What should be done to make logger append to log (not overwrite)?
- Is it possible to log file and line using format variables (only to file)?
I had explored boost::log documentation but had not found answers for these
questions.
Thank you in advance.
Yuriy Petrovskiy
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk