GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ADFLogMessage.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
25 #ifndef ADF_LogMessage
26 #define ADF_LogMessage
27 #define ADF_LOGMESSAGE_H _LogMessage
28 
29 #include <iostream>
30 #include <sstream>
31 
32 namespace ADF {
33 
34 class LogCollector;
35 
37 
81 {
82  friend LogMessage &info(LogMessage &);
83  friend LogMessage &warning(LogMessage &);
84  friend LogMessage &error(LogMessage &);
85  friend LogMessage &debug(LogMessage &);
86  friend LogMessage &dolog(LogMessage &);
87  friend LogMessage &clear(LogMessage &);
88  friend LogMessage &endl(LogMessage &);
89  friend LogMessage &nline(LogMessage &);
90 
91  friend LogMessage &sep(LogMessage &);
92 
93 public:
95  enum ELevel { kError, kWarning, kInfo, kOut } ;
96 
97 private:
99  static short gDebug;
100 
101 private:
103  static short gkMaxDepth;
105  static short gkAutoClear;
106 
107 private:
109  std::string fProcessName;
111  std::string fProcessMethod;
113  std::string fProcessMethodTicket;
114 
116  unsigned int fProcessID;
118  void *fProcessPtr;
119 
120 private:
122  short fDebug;
123 
124 private:
126  unsigned int fTicketNumber;
128  ELevel fLevel;
130  ELevel fLowestLevel;
132  unsigned short fVerbosity;
133 
134 private:
136  unsigned short fIndentation;
138  unsigned short fRealIndentation;
140  bool fIsANewLine;
141 
142 private:
144  std::ostringstream fHeader;
146  std::ostringstream fCoreMsg;
148  std::ostringstream fFooter;
149 
150 protected:
151  void NewTicket();
152 
153 protected:
155  virtual void Indent();
157  virtual void Indent(std::ostream &);
159  virtual void DoClear();
160 
161 public:
162  LogMessage(const char *pname, unsigned int pid = 0u);
163  virtual ~LogMessage();
164 
166  static void SetLogParameters(short global_debug_level = 0, short max_indent = 5, short max_before_clear = 7);
167  static void SetDebug(short global_debug_level = 0);
168 
170  bool IsDebug(short debug_to_test) const
171  { return debug_to_test <= gDebug; }
172 
174 
190  virtual std::ostringstream &operator() ()
191  { return fCoreMsg; }
192 
194  virtual unsigned int GetPID() const
195  { return fProcessID; }
197  virtual void SetPID(unsigned int pid)
198  { fProcessID = pid; }
200 
206  virtual void SetProcessPtr(void *address)
207  { fProcessPtr = address; }
208 
210  virtual std::string &GetProcessName()
211  { return fProcessName; }
213  virtual std::string &GetProcessMethod()
214  { return fProcessMethod; }
215 
217 
247  virtual void SetProcessMethod(const char *);
248 
250  virtual void SetLevel(ELevel lev, unsigned short verbosity = 0u);
252  virtual ELevel GetLevel() const
253  { return fLevel; }
255  virtual ELevel GetLowestLevel() const
256  { return fLowestLevel; }
258  virtual void SetVerboseLevel(unsigned short verbosity)
259  { fVerbosity = verbosity; }
261  virtual unsigned short GetVerboseLevel() const
262  { return fVerbosity; }
263 
265  virtual void Send();
267  virtual std::string Message() const
268  { return fCoreMsg.str() ; }
270  virtual void ClearMessage();
271 
273  virtual std::string Header() const
274  { return fHeader.str() ; }
276  virtual std::string Footer() const
277  { return fFooter.str() ; }
278 
281  { (*pf)(*this); return (*this); }
282 
284  template<class T> LogMessage &operator<<(T t)
285  {
286  if ( fDebug > gDebug )
287  return (*this);
288 
289  // it requires a new ticket to be open
290  if ( fIndentation == 0 )
291  NewTicket();
292 
293  if ( fIsANewLine ) {
294  Indent(fCoreMsg); fIsANewLine = false;
295  }
296  fCoreMsg << t;
297  return (*this);
298  }
299 
300 };
301 
303 LogMessage &info(LogMessage &);
304 LogMessage &warning(LogMessage &);
305 LogMessage &error(LogMessage &);
306 LogMessage &debug(LogMessage &);
307 LogMessage &dolog(LogMessage &);
308 
310 LogMessage &clear(LogMessage &);
311 LogMessage &nline(LogMessage &);
312 LogMessage &sep(LogMessage &);
313 
314 std::ostream &hline (std::ostream &);
315 
316 // deprecated
317 LogMessage &endl(LogMessage &);
318 
319 }
320 
321 #endif
322 
323 
324 
325 
326 
friend LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual void SetLevel(ELevel lev, unsigned short verbosity=0u)
To get the current level of the message.
virtual ELevel GetLevel() const
To get the current level of the message.
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
static void SetDebug(short global_debug_level=0)
virtual ~LogMessage()
should purge the message
LogMessage & clear(LogMessage &)
others
virtual std::ostringstream & operator()()
Allow to pass the underlying stream to funtions/methods.
LogMessage & error(LogMessage &)
std::ostream & hline(std::ostream &)
friend LogMessage & sep(LogMessage &)
LogMessage(const char *pname, unsigned int pid=0u)
virtual std::string & GetProcessMethod()
To get the current method.
friend LogMessage & endl(LogMessage &)
virtual LogMessage & operator<<(LogMessage &(*pf)(LogMessage &))
To allow manipulators.
friend LogMessage & clear(LogMessage &)
others
LogMessage & debug(LogMessage &)
virtual void SetPID(unsigned int pid)
To set the Process ID number.
virtual void SetProcessMethod(const char *)
To set the current method.
bool IsDebug(short debug_to_test) const
to test if the required debug level is lower that the global one
LogMessage & nline(LogMessage &)
LogMessage & sep(LogMessage &)
virtual std::string Message() const
To get the current message.
friend LogMessage & error(LogMessage &)
ELevel
message level
Definition: ADFLogMessage.h:95
virtual void Indent()
to format the output string ... increase indent level
virtual void ClearMessage()
To clear the current message.
friend LogMessage & debug(LogMessage &)
Base class for a Log message.
Definition: ADFLogMessage.h:80
friend LogMessage & warning(LogMessage &)
static void SetLogParameters(short global_debug_level=0, short max_indent=5, short max_before_clear=7)
to modify the global parameters
virtual std::string Header() const
To get the header of the current message.
virtual ELevel GetLowestLevel() const
To get the current level of the message.
virtual unsigned short GetVerboseLevel() const
To get the current level of the message.
virtual void SetVerboseLevel(unsigned short verbosity)
To get the current level of the message.
LogMessage & dolog(LogMessage &)
virtual std::string & GetProcessName()
To get the Process name.
virtual void Send()
To send the message to the log collector.
LogMessage & operator<<(T t)
send any request to the underlying ostringstream
virtual void SetProcessPtr(void *address)
To set the Process address.
friend LogMessage & dolog(LogMessage &)
LogMessage & endl(LogMessage &)
virtual std::string Footer() const
To get the Footer of the current message.
virtual unsigned int GetPID() const
To get the Process ID number.
friend LogMessage & nline(LogMessage &)
LogMessage & warning(LogMessage &)
virtual void DoClear()
really clear the message