Line data Source code
1 : #ifndef SOCIAL_NETWORK_MICROSERVICES_LOGGER_H
2 : #define SOCIAL_NETWORK_MICROSERVICES_LOGGER_H
3 :
4 : #include <boost/log/trivial.hpp>
5 : #include <boost/log/utility/setup/console.hpp>
6 : #include <boost/log/utility/setup/common_attributes.hpp>
7 :
8 : #include <string.h>
9 :
10 : namespace social_network {
11 : #define __FILENAME__ \
12 : (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
13 : #define LOG(severity) \
14 : BOOST_LOG_TRIVIAL(severity) << "(" << __FILENAME__ << ":" \
15 : << __LINE__ << ":" << __FUNCTION__ << ") "
16 :
17 1 : void init_logger() {
18 : boost::log::register_simple_formatter_factory
19 1 : <boost::log::trivial::severity_level, char>("Severity");
20 1 : boost::log::add_common_attributes();
21 : boost::log::add_console_log(
22 1 : std::cerr, boost::log::keywords::format =
23 1 : "[%TimeStamp%] <%Severity%>: %Message%");
24 2 : boost::log::core::get()->set_filter (
25 2 : boost::log::trivial::severity >= boost::log::trivial::info
26 1 : );
27 1 : }
28 :
29 :
30 : } //namespace social_network
31 :
32 : #endif //SOCIAL_NETWORK_MICROSERVICES_LOGGER_H
|