LDMX Software
Logger.h
1#ifndef FRAMEWORK_LOGGER_H
2#define FRAMEWORK_LOGGER_H
3
10#define BOOST_ALL_DYN_LINK 1
11
12#include <boost/log/core.hpp> //core logging service
13#include <boost/log/expressions.hpp> //for attributes and expressions
14#include <boost/log/sinks/sync_frontend.hpp> //syncronous sink frontend
15#include <boost/log/sinks/text_ostream_backend.hpp> //output stream sink backend
16#include <boost/log/sources/global_logger_storage.hpp> //for global logger default
17#include <boost/log/sources/severity_channel_logger.hpp> //for the severity logger
18#include <boost/log/sources/severity_feature.hpp> //for the severity feature in a logger
19#include <boost/log/utility/setup/common_attributes.hpp>
20
21// TODO check which headers are required
22#include <boost/log/sources/record_ostream.hpp>
23#include <boost/log/utility/setup/file.hpp>
24
25#include "Framework/Configure/Parameters.h"
26
27namespace framework {
28
29namespace logging {
30
34enum level {
35 trace = -1,
36 debug = 0,
37 info,
38 warn,
39 error,
40 fatal
41};
42
46namespace log = boost::log;
47namespace sinks = boost::log::sinks;
48
52typedef log::sources::severity_channel_logger_mt<level, std::string> logger;
53
66logger makeLogger(const std::string& name);
67
79void open(const framework::config::Parameters& p);
80
84void close();
85
94class Formatter {
95 int event_number_{0};
96 Formatter() = default;
97
98 public:
100 Formatter(Formatter const&) = delete;
101
103 void operator=(Formatter const&) = delete;
104
106 static Formatter& get();
107
109 static void set(int n);
110
118 void operator()(const log::record_view& view, log::formatting_ostream& os);
119};
120
121} // namespace logging
122
123} // namespace framework
124
138#define enableLogging(name) \
139 mutable ::framework::logging::logger theLog_{ \
140 ::framework::logging::makeLogger(name)};
141
148#define ldmx_log(lvl) BOOST_LOG_SEV(theLog_, ::framework::logging::level::lvl)
149
150#endif // FRAMEWORK_LOGGER_H
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:29
Our logging formatter.
Definition Logger.h:94
Formatter(Formatter const &)=delete
delete the copy constructor
void operator=(Formatter const &)=delete
delete the assignment operator
void operator()(const log::record_view &view, log::formatting_ostream &os)
format the passed record view into the output stream
Definition Logger.cxx:160
static Formatter & get()
get reference to the current single Formatter
Definition Logger.cxx:153
static void set(int n)
set the event number in the current Formatter
Definition Logger.cxx:158
All classes in the ldmx-sw project use this namespace.
Definition PerfDict.cxx:45