GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Messenger.h
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \class genie::Messenger
5 
6 \brief A more convenient interface to the log4cpp Message Service
7 
8 \author Costas Andreopoulos <c.andreopoulos \at cern.ch>
9  University of Liverpool
10 
11 \created June 16, 2004
12 
13 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
14  For the full text of the license visit http://copyright.genie-mc.org
15 */
16 //____________________________________________________________________________
17 
18 #ifndef _MESSENGER_H_
19 #define _MESSENGER_H_
20 
21 #include <iostream>
22 #include <cstring>
23 #include <string>
24 #include <map>
25 
26 // ROOT5 has difficulty with parsing log4cpp headers
27 #if !defined(__CINT__) && !defined(__MAKECINT__)
28  #include "log4cpp/Category.hh"
29  #include "log4cpp/Appender.hh"
30  #include "log4cpp/OstreamAppender.hh"
31  #include "log4cpp/BasicLayout.hh"
32  #include "log4cpp/Priority.hh"
33 #else
34  namespace log4cpp {
35  class Priority {
36  typedef int Value;
37  };
38  class Category;
39  }
40 #endif
41 
42 #include "Framework/Conventions/GBuild.h"
43 
44 using std::string;
45 
46 // comment defined priority levels for the document generator
47 /*! \def pFATAL \brief Defines the FATAL priority level */
48 /*! \def pALERT \brief Defines the ALERT priority level */
49 /*! \def pCRIT \brief Defines the CRIT priority level */
50 /*! \def pERROR \brief Defines the ERROR priority level */
51 /*! \def pWARN \brief Defines the WARN priority level */
52 /*! \def pNOTICE \brief Defines the NOTICE priority level */
53 /*! \def pINFO \brief Defines the INFO priority level */
54 /*! \def pDEBUG \brief Defines the DEBUG priority level */
55 
56 #define pFATAL log4cpp::Priority::FATAL
57 #define pALERT log4cpp::Priority::ALERT
58 #define pCRIT log4cpp::Priority::CRIT
59 #define pERROR log4cpp::Priority::ERROR
60 #define pWARN log4cpp::Priority::WARN
61 #define pNOTICE log4cpp::Priority::NOTICE
62 #define pINFO log4cpp::Priority::INFO
63 #define pDEBUG log4cpp::Priority::DEBUG
64 
65 /*! \def ENDL \brief A shortcut for log4cpp's CategoryStream::ENDLINE or std manipulators*/
66 
67 #ifdef __GENIE_USES_LOG4CPP_VERSION__
68  #if __GENIE_USES_LOG4CPP_VERSION__==0
69  #define ENDL log4cpp::CategoryStream::ENDLINE
70  #else
71  #define ENDL std::endl
72  #endif
73 #else
74  #define ENDL std::endl
75 #endif
76 
77 /*!
78  \def SLOG(stream, priority)
79  \brief A macro that returns the requested log4cpp::Category
80  appending a short string (using the __FUNCTION__ and __LINE__ macros)
81  with information for the calling method [produces short message].
82 */
83 
84 #define SLOG(stream, priority) \
85  (*Messenger::Instance())(stream) \
86  << priority << "[s] <" \
87  << __FUNCTION__ << " (" << __LINE__ << ")> : "
88 
89 /*!
90  \def LOG(stream, priority)
91  \brief A macro that returns the requested log4cpp::Category
92  appending a string (using the __FILE__, __FUNCTION__ and __LINE__ macros)
93  with information for the calling method [produces normal messages].
94 */
95 
96 #define LOG(stream, priority) \
97  (*Messenger::Instance())(stream) \
98  << priority << "[n] <" \
99  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
100 
101 /*!
102  \def HIDE_GENIE_MSG_LOG_MACROS
103  \brief Use this cpp flag variable to ensure LOG_DEBUG ... LOG_FATAL macros are not exposed.
104  This allows this header to be used in conjunction with the art framework's
105  conflicting MessengeFacility's macros of the same name. The two argument
106  LOG macro (see above) is still available for use.
107  Currently this comes up only via Algorithm.h's inclusion of Algorithm.icc
108  which included Messenger.h.
109 */
110 #ifndef HIDE_GENIE_MSG_LOG_MACROS
111 
112 #define LOG_FATAL(stream) \
113  (*Messenger::Instance())(stream) \
114  << log4cpp::Priority::FATAL << "[n] <" \
115  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
116 
117 #define LOG_ALERT(stream) \
118  (*Messenger::Instance())(stream) \
119  << log4cpp::Priority::ALERT << "[n] <" \
120  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
121 
122 #define LOG_CRIT(stream) \
123  (*Messenger::Instance())(stream) \
124  << log4cpp::Priority::CRIT << "[n] <" \
125  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
126 
127 #define LOG_ERROR(stream) \
128  (*Messenger::Instance())(stream) \
129  << log4cpp::Priority::ERROR << "[n] <" \
130  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
131 
132 #define LOG_WARN(stream) \
133  (*Messenger::Instance())(stream) \
134  << log4cpp::Priority::WARN << "[n] <" \
135  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
136 
137 #define LOG_NOTICE(stream) \
138  (*Messenger::Instance())(stream) \
139  << log4cpp::Priority::NOTICE << "[n] <" \
140  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
141 
142 #define LOG_INFO(stream) \
143  (*Messenger::Instance())(stream) \
144  << log4cpp::Priority::INFO << "[n] <" \
145  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
146 
147 #define LOG_DEBUG(stream) \
148  (*Messenger::Instance())(stream) \
149  << log4cpp::Priority::DEBUG << "[n] <" \
150  << __FILE__ << "::" << __FUNCTION__ << " (" << __LINE__ << ")> : "
151 
152 #endif // HIDE_GENIE_MSG_LOG_MACROS
153 
154 /*!
155  \def LLOG(stream, priority)
156  \brief A macro that returns the requested log4cpp::Category
157  appending a string (using the __PRETTY_FUNCTION__ and __LINE__ macros)
158  with information for the calling method [produces long messages].
159 */
160 
161 #define LLOG(stream, priority) \
162  (*Messenger::Instance())(stream) \
163  << priority << "[l] <" \
164  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
165 
166 #define LLOG_FATAL(stream) \
167  (*Messenger::Instance())(stream) \
168  << log4cpp::Priority::FATAL << "[l] <" \
169  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
170 
171 #define LLOG_ALERT(stream) \
172  (*Messenger::Instance())(stream) \
173  << log4cpp::Priority::ALERT << "[l] <" \
174  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
175 
176 #define LLOG_CRIT(stream) \
177  (*Messenger::Instance())(stream) \
178  << log4cpp::Priority::CRIT << "[l] <" \
179  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
180 
181 #define LLOG_ERROR(stream) \
182  (*Messenger::Instance())(stream) \
183  << log4cpp::Priority::ERROR << "[l] <" \
184  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
185 
186 #define LLOG_WARN(stream) \
187  (*Messenger::Instance())(stream) \
188  << log4cpp::Priority::WARN << "'[l] <" \
189  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
190 
191 #define LLOG_NOTICE(stream) \
192  (*Messenger::Instance())(stream) \
193  << log4cpp::Priority::NOTICE << "[l] <" \
194  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
195 
196 #define LLOG_INFO(stream) \
197  (*Messenger::Instance())(stream) \
198  << log4cpp::Priority::INFO << "[l] <" \
199  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
200 
201 #define LLOG_DEBUG(stream) \
202  (*Messenger::Instance())(stream) \
203  << log4cpp::Priority::DEBUG << "[l] <" \
204  << __PRETTY_FUNCTION__ << " (" << __LINE__ << ")> : "
205 
206 /*!
207  \def BLOG(stream, priority)
208  \brief A macro that returns the requested log4cpp::Category appending no
209  additional information
210 */
211 
212 #define BLOG(stream, priority) \
213  (*Messenger::Instance())(stream) << priority
214 
215 /*!
216  \def MAXSLOG(stream, priority, maxcount)
217  \brief Similar to SLOG(stream,priority) but quits after "maxcount" messages
218 
219  \def MAXLOG(stream, priority, maxcount)
220  \brief Similar to LOG(stream,priority) but quits after "maxcount" messages
221 
222  \def MAXLLOG(stream, priority, maxcount)
223  \brief Similar to LLOG(stream,priority) but quits after "maxcount" messages
224 
225 
226 */
227 
228 // Macro to concatenate two symbols:
229 #define TOKCAT(x,y) x##y
230 // Macro to expand preprocessor variables and concatenate:
231 #define TOKCAT2(x,y) TOKCAT(x,y)
232 // Macro to concatenate source line with a symbol:
233 #define LINECAT(x) TOKCAT2(x, __LINE__ )
234 
235 #define MAXSLOG(s,l,c) \
236  static int LINECAT(MSGCNT) = 0; \
237  const char* LINECAT(MSGADD) = (++LINECAT(MSGCNT)==c) ? "..Last Message .. " : ""; \
238  if (LINECAT(MSGCNT) > c || LINECAT(MSGCNT) < 0) \
239  {;} else SLOG(s,l) << LINECAT(MSGADD)
240 
241 #define MAXLOG(s,l,c) \
242  static int LINECAT(MSGCNT) = 0; \
243  const char* LINECAT(MSGADD) = (++LINECAT(MSGCNT)==c) ? "..Last Message .. " : ""; \
244  if (LINECAT(MSGCNT) > c || LINECAT(MSGCNT) < 0) \
245  {;} else LOG(s,l) << LINECAT(MSGADD)
246 
247 #define MAXLLOG(s,l,c) \
248  static int LINECAT(MSGCNT) = 0; \
249  const char* LINECAT(MSGADD) = (++LINECAT(MSGCNT)==c) ? "..Last Message .. " : ""; \
250  if (LINECAT(MSGCNT) > c || LINECAT(MSGCNT) < 0) \
251  {;} else LLOG(s,l) << LINECAT(MSGADD)
252 
253 
254 namespace genie {
255 
256 extern bool gAbortingInErr;
257 
259 {
260 public:
261  static Messenger * Instance(void);
262 
263  log4cpp::Category & operator () (const char * stream);
264  void SetPriorityLevel(const char * stream, log4cpp::Priority::Value p);
265 
266  bool SetPrioritiesFromXmlFile(string filename);
267 
268 private:
269  Messenger();
270  Messenger(const Messenger & config_pool);
271  virtual ~Messenger();
272 
274 
275  void Configure(void);
276 
277  log4cpp::Priority::Value PriorityFromString(string priority);
278 
279  struct Cleaner {
282  if (Messenger::fInstance !=0) {
283  delete Messenger::fInstance;
285  }
286  }
287  };
288  friend struct Cleaner;
289 };
290 
291 } // genie namespace
292 #endif // _MESSENGER_H_
void DummyMethodAndSilentCompiler()
Definition: Messenger.h:280
virtual ~Messenger()
Definition: Messenger.cxx:44
log4cpp::Priority::Value PriorityFromString(string priority)
Definition: Messenger.cxx:192
log4cpp::Category & operator()(const char *stream)
Definition: Messenger.cxx:81
void Configure(void)
Definition: Messenger.cxx:96
bool SetPrioritiesFromXmlFile(string filename)
Definition: Messenger.cxx:114
static Messenger * Instance(void)
Definition: Messenger.cxx:49
A more convenient interface to the log4cpp Message Service.
Definition: Messenger.h:258
void SetPriorityLevel(const char *stream, log4cpp::Priority::Value p)
Definition: Messenger.cxx:88
bool gAbortingInErr
Definition: Messenger.cxx:34
static Messenger * fInstance
Definition: Messenger.h:273