End of day commit
This commit is contained in:
+2
-1
@@ -9,11 +9,12 @@ class Logger {
|
||||
public:
|
||||
Logger();
|
||||
~Logger() {};
|
||||
void trace(std::string str);
|
||||
void debug(std::string str);
|
||||
void info(std::string str);
|
||||
void warning(std::string str);
|
||||
void error(std::string str);
|
||||
void critical(std::string str);
|
||||
void fatal(std::string str);
|
||||
|
||||
private:
|
||||
static void formatter(boost::log::record_view const& rec, boost::log::formatting_ostream& strm);
|
||||
|
||||
+45
-24
@@ -1,4 +1,5 @@
|
||||
#include <boost/log/common.hpp>
|
||||
#include <boost/smart_ptr/make_shared_object.hpp>
|
||||
#include <boost/log/sinks.hpp>
|
||||
#include <boost/log/sources/severity_logger.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
@@ -9,7 +10,8 @@
|
||||
#include <boost/core/null_deleter.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "Logger.h"
|
||||
|
||||
@@ -25,43 +27,62 @@ Logger::Logger() {
|
||||
boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity");
|
||||
Logger::sink = boost::make_shared<text_sink>();
|
||||
|
||||
boost::shared_ptr<std::ostream> stdout_stream{&std::clog, boost::null_deleter{}};
|
||||
Logger::sink->locked_backend()->add_stream(stdout_stream);
|
||||
|
||||
add_file_log
|
||||
logging::add_file_log
|
||||
(
|
||||
keywords::file_name = "concatenator_%N.log",
|
||||
keywords::rotation_size = 10 * 1024 * 1024,
|
||||
keywords::format = (
|
||||
expr::stream <<
|
||||
"[" <<
|
||||
expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") <<
|
||||
"] [" <<
|
||||
logging::trivial::severity <<
|
||||
"] --- " <<
|
||||
expr::smessage
|
||||
)
|
||||
keywords::rotation_size = 10 * 1024 * 1024
|
||||
);
|
||||
Logger::sink->set_formatter
|
||||
(
|
||||
expr::stream <<
|
||||
"[" <<
|
||||
expr::format_date_time< boost::posix_time::ptime >("TimeStamp", "%Y-%m-%d %H:%M:%S") <<
|
||||
"] [" <<
|
||||
logging::trivial::severity <<
|
||||
"] --- " <<
|
||||
expr::smessage
|
||||
);
|
||||
|
||||
logging::add_common_attributes();
|
||||
Logger::sink->set_filter(severity > 0);
|
||||
|
||||
boost::shared_ptr<std::ostream> stdout_stream{&std::clog, boost::null_deleter{}};
|
||||
Logger::sink->locked_backend()->add_stream(stdout_stream);
|
||||
Logger::sink->locked_backend()->add_stream(boost::make_shared< std::ofstream >("sample.log"));
|
||||
|
||||
//Logger::sink->set_filter(severity > 0);
|
||||
|
||||
logging::core::get()->add_sink(Logger::sink);
|
||||
|
||||
logging::add_common_attributes();
|
||||
|
||||
};
|
||||
|
||||
void Logger::trace(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::trace) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::debug(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::debug) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::info(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::info) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::warning(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::warning) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::error(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::error) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::info(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::error) << str;
|
||||
void Logger::fatal(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::fatal) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
void Logger::warning(std::string str) {
|
||||
BOOST_LOG_SEV(lg, logging::trivial::error) << str;
|
||||
Logger::sink->flush();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user