22#define BOOST_LOG_DYN_LINK
23#include <boost/date_time.hpp>
24#include <boost/filesystem.hpp>
25#include <boost/log/trivial.hpp>
26#include <boost/log/expressions.hpp>
27#include <boost/log/support/date_time.hpp>
28#include <boost/log/utility/manipulators.hpp>
29#include <boost/log/utility/setup.hpp>
36BOOST_LOG_ATTRIBUTE_KEYWORD(Location,
"Location", media::Logger::Location)
37BOOST_LOG_ATTRIBUTE_KEYWORD(Timestamp,
"Timestamp", boost::posix_time::ptime)
49 boost::log::formatter formatter = boost::log::expressions::stream
50 <<
"[" << attrs::Severity <<
" "
51 << boost::log::expressions::format_date_time< boost::posix_time::ptime >(
"Timestamp",
"%Y-%m-%d %H:%M:%S.%f")
53 << boost::log::expressions::if_(boost::log::expressions::has_attr(attrs::Location))
55 boost::log::expressions::stream <<
"[" << attrs::Location <<
"] "
57 << boost::log::expressions::smessage;
59 boost::log::core::get()->remove_all_sinks();
60 auto logger = boost::log::add_console_log(std::cout);
61 logger->set_formatter(formatter);
66 boost::ignore_unused_variable_warning(severity);
72 void Log(Severity severity,
const std::string& message,
const boost::optional<Location> &loc) {
76 if (
auto rec = boost::log::trivial::logger::get().open_record()) {
77 boost::log::record_ostream out{rec};
78 out << boost::log::add_value(attrs::Severity, severity)
79 << boost::log::add_value(attrs::Timestamp, boost::posix_time::microsec_clock::universal_time())
86 out << boost::log::add_value(attrs::Location, tmp);
89 boost::log::trivial::logger::get().push_record(std::move(rec));
97std::shared_ptr<media::Logger>& MutableInstance() {
98 static std::shared_ptr<media::Logger> instance{
new BoostLogLogger()};
102void SetInstance(
const std::shared_ptr<media::Logger>& logger) {
103 MutableInstance() = logger;
112 Log(Severity::kDebug, message, location);
116 Log(Severity::kInfo, message, location);
120 Log(Severity::kWarning, message, location);
124 Log(Severity::kError, message, location);
128 Log(Severity::kFatal, message, location);
143 default:
return strm << static_cast<uint>(severity);
152 return *MutableInstance();