MessageLoggerConfig.h
Go to the documentation of this file.
1 #ifndef _utl_MessageLoggerConfig_h_
2 #define _utl_MessageLoggerConfig_h_
3 
4 // Just need forward-declarations, tough being nested
5 // utl::MessageLogger::Message we have to included the file.
6 #include <utl/MessageLogger.h>
7 //
8 #include <fstream>
9 #include <memory>
10 
11 
12 namespace utl {
13 
14  class Branch;
15 
16 
30  public:
32  MessageLoggerConfig(MessageLogger& l, const Branch& config);
33 
36 
38  MessageLoggerConfig(const Branch& config);
39 
42 
43  void Configure(const Branch& config);
44 
46  void ApplyConfiguration();
47 
49  const unsigned int& GetLevel() const
50  { return fLevel; /* We could, of course, be returning a copy.*/ }
51 
53  unsigned int& GetLevel() { return fLevel; }
54 
56  void SetLevel(unsigned int vl) { fLevel = vl; }
57 
61  template<typename T>
62  MessageLogger::Message operator()(const T& message, unsigned int level = 0, bool trailEOL = true)
63  { return fTheLogger(message, level, trailEOL); }
64 
66  template<class S>
67  void
68  ApplyConfigurationOn(S& stream)
69  const
70  {
71  // Forward the call:
72  // (maybe, at last, MessageLoggerConfig and MessageLogger should
73  // be the same class; on the other hand this class handles the
74  // eventual file, and loading from branch).
75  fTheLogger.ApplyConfigurationOn(stream);
76  }
77 
78  private:
79  void LoadConfiguration(const Branch& config);
80 
84  unsigned int fLevel = 0;
85 
87  unsigned int fNPrecDigits = 0;
88 
90  unsigned int fFlushPeriod = 0;
91 
93  std::ofstream fOutput;
94 
96  std::string fOutputFilename;
97 
99  std::unique_ptr<MessageLogger> fOwnLogger;
100 
103  };
104 
105 
117  template<class Stream>
118  inline
119  Stream&
121  {
122  mlc.ApplyConfigurationOn(s);
123  return s;
124  }
125 
126 }
127 
128 
129 #endif
void ApplyConfiguration()
Apply already loaded configuration.
void LoadConfiguration(const Branch &config)
std::ofstream fOutput
Output message sink.
Stream & operator<<(Stream &s, MessageLoggerConfig &mlc)
Applies the configuration to the given stream.
MessageLogger::Message operator()(const T &message, unsigned int level=0, bool trailEOL=true)
Class representing a document branch.
Definition: Branch.h:107
Wraps a message to logger (received as parameter or created here), its access and configuration...
unsigned int fFlushPeriod
The period.
constexpr double s
Definition: AugerUnits.h:163
const unsigned int & GetLevel() const
Retrieve (read-only) the current level of verbosity.
#define S
void Configure(const Branch &config)
std::unique_ptr< MessageLogger > fOwnLogger
Pointer to self created logger.
unsigned int & GetLevel()
Retrieve by reference the current level of verbosity.
unsigned int fNPrecDigits
Precission digits.
std::string fOutputFilename
Output log filename (if empty, then cout).
Handle diagnosis messages output.
Definition: MessageLogger.h:38
MessageLogger & fTheLogger
The logger to configure.
void SetLevel(unsigned int vl)
Change the level of verbosity.
MessageLoggerConfig()
Create a configurator without any configuration yet.

, generated on Tue Sep 26 2023.