JayBeams  0.1
Another project to have fun coding.
log.hpp
Go to the documentation of this file.
1 #ifndef jb_log_hpp
2 #define jb_log_hpp
3 
4 #include <jb/config_object.hpp>
6 
7 #include <boost/log/sources/global_logger_storage.hpp>
8 #include <boost/log/sources/record_ostream.hpp>
9 #include <boost/log/sources/severity_logger.hpp>
10 #include <boost/log/utility/manipulators/add_value.hpp>
11 
12 #ifndef JB_MIN_LOG_LEVEL
13 #define JB_MIN_LOG_LEVEL debug
14 #endif // JB_MIN_LOG_LEVEL
15 
16 namespace jb {
17 
18 /// Statically check if the severity level should even be compiled in.
21 }
22 
23 /// Logging functions and objects for JayBeams
24 namespace log {
25 
26 /**
27  * Configuration object for the logging functions.
28  */
29 class config : public jb::config_object {
30 public:
31  config();
33 
43 
44  void validate() const override;
45 };
46 
47 /// Initialize the logging functions using the configuration provided
48 void init(config const& cfg = config());
49 
50 /// Define the global logger for JayBeams
52  logger, boost::log::sources::severity_logger_mt<severity_level>)
53 
54 void next_tid();
55 
56 } // namespace log
57 
58 } // namespace jb
59 
60 #define JB_LOG_I(logger, lvl, rec_var) \
61  if (not::jb::severity_static_predicate(lvl)) { \
62  } else \
63  for (::boost::log::record rec_var = \
64  (logger).open_record(boost::log::keywords::severity = lvl); \
65  !!rec_var;) \
66  ::boost::log::aux::make_record_pump((logger), rec_var).stream() \
67  << boost::log::add_value("Filename", __FILE__) \
68  << boost::log::add_value("Lineno", static_cast<int>(__LINE__))
69 
70 #define JB_LOG(lvl) \
71  JB_LOG_I( \
72  ::jb::log::logger::get(), jb::severity_level::lvl, \
73  BOOST_LOG_UNIQUE_IDENTIFIER_NAME(jb_log_record_))
74 
75 #define JB_LOG_VAR(lvl) \
76  JB_LOG_I( \
77  ::jb::log::logger::get(), lvl, \
78  BOOST_LOG_UNIQUE_IDENTIFIER_NAME(jb_log_record_))
79 
80 #endif // jb_log_hpp
jb::config_attribute< config, bool > enable_file_logging
Definition: log.hpp:37
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(logger, boost::log::sources::severity_logger_mt< severity_level >) void next_tid()
Define the global logger for JayBeams.
severity_level
Severity levels for JayBeams, based on syslog.
Base class for all configuration objects.
jb::config_attribute< config, std::string > logfile_basename
Definition: log.hpp:38
void validate() const override
Validate the settings.
Definition: log.cpp:115
#define JB_MIN_LOG_LEVEL
Definition: log.hpp:13
Configuration object for the logging functions.
Definition: log.hpp:29
jb::config_attribute< config, std::string > logfile_archive_directory
Definition: log.hpp:40
jb::config_attribute< config, long > maximum_size_archived
Definition: log.hpp:41
void init(config const &cfg)
Initialize the logging functions using the configuration provided.
Definition: log.cpp:190
jb::config_attribute< config, std::string > logfile_suffix
Definition: log.hpp:39
config_object_constructors(config)
Helper class to easily define configuration attributes.
jb::config_attribute< config, jb::severity_level > minimum_console_severity
Definition: log.hpp:35
void next_tid()
Definition: log.cpp:186
constexpr bool severity_static_predicate(jb::severity_level lvl)
Statically check if the severity level should even be compiled in.
Definition: log.hpp:19
jb::config_attribute< config, jb::severity_level > minimum_severity
Definition: log.hpp:34
jb::config_attribute< config, bool > enable_console_logging
Definition: log.hpp:36
jb::config_attribute< config, long > minimum_free_space
Definition: log.hpp:42
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7