I am using the example at the following link.
My code is as follows.
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/settings.hpp>
#include <boost/log/utility/setup/from_settings.hpp>
#include <boost/regex.hpp>
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
#define BOOST_LOG_DYN_LINK 1
int main(int, char*[])
{
//init_logging();
std::ifstream file("settings.ini");
logging::init_from_stream(file);
BOOST_LOG_TRIVIAL(trace) << "This is a trace severity message";
BOOST_LOG_TRIVIAL(debug) << "This is a debug severity message";
BOOST_LOG_TRIVIAL(info) << "This is an informational severity message";
BOOST_LOG_TRIVIAL(warning) << "This is a warning severity message";
BOOST_LOG_TRIVIAL(error) << "This is an error severity message";
BOOST_LOG_TRIVIAL(fatal) << "and this is a fatal severity message";
return 0;
}
My settings.ini file look as follows.
# Logging core settings section. May be omitted if no parameters specified within it.
[Core]
DisableLogging=false
Filter="%Severity% > 3"
# Sink settings sections
[Sinks.MySink1]
# Sink destination type
Destination=TextFile
FileName="MyApp.log"
RotationSize=1024
# Formatter string. Optional, by default only log record message text is written.
Format="<%TimeStamp%> - %Message%"
# The flag shows whether the sink should be asynchronous
Asynchronous=false
However no file is getting created. What am I doing wrong?
Everything works right up until you add the filter:
Googling a bit (via Boost.Log Configuration Files e.g.) I found:
Add it like:
Now, fix the filter expression to use the text representation:
In similar vein, you need to add the
TimeStamp
attribute to core:Now it all works:
Which writes to MyApp.log:
Added Demo Live On Coliru