I am using the BOOST_LOG_GLOBAL_LOGGER_INIT template to set up my global logger. Here is the code:
HEADER
#include<boost/log/expressions.hpp>#include<boost/log/sources/global_logger_storage.hpp>#include<boost/log/support/date_time.hpp>#include<boost/log/trivial.hpp>#include<boost/log/utility/setup.hpp>#include<boost/log/utility/setup/file.hpp>#define INFO BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::info)#define WARN BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::warning)#define ERROR BOOST_LOG_SEV(my_logger::get(), boost::log::trivial::error)#define SYS_LOGFILE "/var/log/example.log"#define APP_LOGFILE "/home/pdl/ClionProjects/WrokingLogger/example.log"namespaceattrs=boost::log::attributes;namespaceexpr=boost::log::expressions;namespacelogging=boost::log;//Narrow-char thread-safe logger.typedefboost::log::sources::severity_logger_mt<boost::log::trivial::severity_level>logger_t;//declares a global logger with a custom initializationBOOST_LOG_GLOBAL_LOGGER(logger,logger_t)
CPP
#include"GlobalLogger.h"//Defines a global logger initialization routineBOOST_LOG_GLOBAL_LOGGER_INIT(logger,logger_t){logger_tlg;logging::add_common_attributes();//logging::add_file_log("sample.log");logging::add_file_log(boost::log::keywords::file_name=APP_LOGFILE,boost::log::keywords::format=(expr::stream<<expr::format_date_time<boost::posix_time::ptime>("TimeStamp","%Y-%m-%d %H:%M:%S")<<" ["<<expr::attr<boost::log::trivial::severity_level>("Severity")<<"]: "<<expr::smessage));logging::add_console_log(std::cout,boost::log::keywords::format=(expr::stream<<expr::format_date_time<boost::posix_time::ptime>("TimeStamp","%Y-%m-%d %H:%M:%S")<<" ["<<expr::attr<boost::log::trivial::severity_level>("Severity")<<"]: "<<expr::smessage));logging::core::get()->set_filter(logging::trivial::severity>logging::trivial::info);returnlg;}
This code is writing to the console perfectly but it's not writing to the file. Looking at the tutorial for writing to a file shows this snippet of code:
My BIG question is where to I put that code? Ideally I want the stream to be set up in the BOOST_LOG_GLOBAL_LOGGER_INIT template method. Can I do this? If yes, any examples of how to do this?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am using the BOOST_LOG_GLOBAL_LOGGER_INIT template to set up my global logger. Here is the code:
HEADER
CPP
main.cpp
This code is writing to the console perfectly but it's not writing to the file. Looking at the tutorial for writing to a file shows this snippet of code:
The full example code is located here: http://www.boost.org/doc/libs/1_54_0/libs/log/example/doc/tutorial_logging.cpp
My BIG question is where to I put that code? Ideally I want the stream to be set up in the BOOST_LOG_GLOBAL_LOGGER_INIT template method. Can I do this? If yes, any examples of how to do this?
Andrey:
Can you delete this post? I got it working.
Thank you.