Logging.h
Go to the documentation of this file.
1 #ifndef WIRECELL_LOGGING
2 #define WIRECELL_LOGGING
3 
4 
5 // SPDLOG_LOGGER_DEBUG() and SPDLOG_LOGGER_TRACE can be used to wrap
6 // very verbose messages and they can be deactivated at compile time
7 // so as to not suffer performance slowdowns. Of course, do not put
8 // code with side effects inside these macros.
9 
10 // Eventually set this via build configuration to DEBUG or maybe INFO.
11 // For development, we keep to trace although default set in wire-cell
12 // CLI are higher.
13 #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
14 
15 #include "spdlog/spdlog.h"
16 #include "spdlog/fmt/ostr.h"
17 
18 #include <string>
19 
20 namespace WireCell {
21 
22  namespace Log {
23 
24  typedef std::shared_ptr<spdlog::logger> logptr_t;
25  typedef std::shared_ptr<spdlog::sinks::sink> sinkptr_t;
26 
27  // WCT maintains a collection of sinks associated with all
28  // loggers created through this API. No sinks are added by
29  // default. The WCT application should add some if output is
30  // wanted. Note, all loggers made from here go to ALL sinks
31  // added. If unique loggers->sinks mapping is needed,
32  // directly use calls in the spdlog:: namespace.
33  void add_sink(sinkptr_t sink, std::string level="");
34 
35  // Add a log file sink with optional level.
37 
38  // Add a standard out console sink with optional level.
39  void add_stdout(bool color=true, std::string level="");
40 
41  // Add a standard err console sink with optional level.
42  void add_stderr(bool color=true, std::string level="");
43 
44  // Get/make a logger by name. If a logger by the name is not
45  // yet existing then it will be created and attached to all
46  // sinks that have been added prior to the call. WCT
47  // components are encouraged to may make unique loggers with
48  // some short name related to the component type/name and hold
49  // on to them for use in their code.
50  logptr_t logger(std::string name);
51 
52  // Set log level. If which is empty the set level of logs.
53  // Otherwise, set the given logger.
55 
56  // Set logging pattern. If which is empty then
57  // set pattern of all sinks. Otherwise, set the given logger.
59  }
60 
61 }
62 
63 #endif
static QCString name
Definition: declinfo.cpp:673
void add_stdout(bool color=true, std::string level="")
Definition: Logging.cxx:48
std::string string
Definition: nybbler.cc:12
std::shared_ptr< spdlog::sinks::sink > sinkptr_t
Definition: Logging.h:25
void set_level(std::string level, std::string which="")
Definition: Logging.cxx:90
void set_pattern(std::string pattern, std::string which="")
Definition: Logging.cxx:100
string filename
Definition: train.py:213
void add_stderr(bool color=true, std::string level="")
Definition: Logging.cxx:59
logptr_t logger(std::string name)
Definition: Logging.cxx:71
std::shared_ptr< spdlog::logger > logptr_t
Definition: Logging.h:24
Definition: Main.h:22
color
Definition: color.h:50
void add_file(std::string filename, std::string level="")
Definition: Logging.cxx:42
std::string pattern
Definition: regex_t.cc:33
void add_sink(sinkptr_t sink, std::string level="")
Definition: Logging.cxx:35