GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GwLogMessage.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 Gw_LogMessage
26 #define Gw_LogMessage
27 #define Gw_LOGMESSAGE_H Gw_LogMessage
28 
29 #include <iostream>
30 #include <sstream>
31 
32 namespace Gw {
33 
34 class LogCollector;
35 class LogMessage;
36 
38  LogMessage &info(LogMessage &);
39  LogMessage &warning(LogMessage &);
40  LogMessage &error(LogMessage &);
41  LogMessage &debug(LogMessage &);
42  LogMessage &dolog(LogMessage &);
43 
45  LogMessage &clear(LogMessage &);
46  LogMessage &nline(LogMessage &);
47 
48  std::ostream &hline (std::ostream &);
49 
51 
95 {
96  friend LogMessage &Gw::info(LogMessage &);
98  friend LogMessage &Gw::error(LogMessage &);
99  friend LogMessage &Gw::debug(LogMessage &);
100  friend LogMessage &Gw::dolog(LogMessage &);
101  friend LogMessage &Gw::clear(LogMessage &);
102  friend LogMessage &Gw::nline(LogMessage &);
103 
104  // friend LogMessage &endl(LogMessage &);
105  // friend LogMessage &sep(LogMessage &);
106 
107 public:
109  enum ELevel { kError, kWarning, kInfo, kOut } ;
110 
111 private:
113  static short gDebug;
114 
115 private:
117  static short gkMaxDepth;
119  static short gkAutoClear;
120 
121 private:
123  std::string fProcessName;
125  std::string fProcessMethod;
127  std::string fProcessMethodTicket;
128 
130  unsigned int fProcessID;
132  void *fProcessPtr;
133 
134 private:
136  short fDebug;
137 
138 private:
140  unsigned int fTicketNumber;
142  ELevel fLevel;
144  ELevel fLowestLevel;
146  unsigned short fVerbosity;
147 
148 private:
150  unsigned short fIndentation;
152  unsigned short fRealIndentation;
154  bool fIsANewLine;
155 
156 private:
158  std::ostringstream fHeader;
160  std::ostringstream fCoreMsg;
162  std::ostringstream fFooter;
163 
164 protected:
165  void NewTicket();
166 
167 protected:
169  virtual void Indent();
171  virtual void Indent(std::ostream &);
173  virtual void DoClear();
174 
175 public:
176  LogMessage(const char *pname, unsigned int pid = 0u);
177  virtual ~LogMessage();
178 
180  static void SetLogParameters(short global_debug_level = 0, short max_indent = 5, short max_before_clear = 7);
181  static void SetDebug(short global_debug_level = 0);
182 
184  bool IsDebug(short debug_to_test) const
185  { return debug_to_test <= gDebug; }
186 
188 
204  virtual std::ostringstream &operator() ()
205  { return fCoreMsg; }
206 
208  virtual unsigned int GetPID() const
209  { return fProcessID; }
211  virtual void SetPID(unsigned int pid)
212  { fProcessID = pid; }
214 
220  virtual void SetProcessPtr(void *address)
221  { fProcessPtr = address; }
222 
224  virtual std::string &GetProcessName()
225  { return fProcessName; }
227  virtual std::string &GetProcessMethod()
228  { return fProcessMethod; }
229 
231 
261  virtual void SetProcessMethod(const char *);
262 
264  virtual void SetLevel(ELevel lev, unsigned short verbosity = 0u);
266  virtual ELevel GetLevel() const
267  { return fLevel; }
269  virtual ELevel GetLowestLevel() const
270  { return fLowestLevel; }
272  virtual void SetVerboseLevel(unsigned short verbosity)
273  { fVerbosity = verbosity; }
275  virtual unsigned short GetVerboseLevel() const
276  { return fVerbosity; }
277 
279  virtual void Send();
281  virtual std::string Message() const
282  { return fCoreMsg.str() ; }
284  virtual void ClearMessage();
285 
287  virtual std::string Header() const
288  { return fHeader.str() ; }
290  virtual std::string Footer() const
291  { return fFooter.str() ; }
292 
295  { (*pf)(*this); return (*this); }
296 
298  template<class T> LogMessage &operator<<(T t)
299  {
300  if ( fDebug > gDebug )
301  return (*this);
302 
303  // it requires a new ticket to be open
304  if ( fIndentation == 0 )
305  NewTicket();
306 
307  if ( fIsANewLine ) {
308  Indent(fCoreMsg); fIsANewLine = false;
309  }
310  fCoreMsg << t;
311  return (*this);
312  }
313 
314 };
315 
316 
317 
318 // deprecated
319 // LogMessage &sep(LogMessage &);
320 // LogMessage &Gw::endl(LogMessage &);
321 
322 } // namespace
323 
324 
325 #endif
326 
327 
328 
329 
330 
virtual void SetPID(unsigned int pid)
To set the Process ID number.
Definition: GwLogMessage.h:211
virtual unsigned short GetVerboseLevel() const
To get the current level of the message.
Definition: GwLogMessage.h:275
LogMessage & error(LogMessage &)
LogMessage & warning(LogMessage &)
std::ostream & hline(std::ostream &)
LogMessage & nline(LogMessage &)
Base class for a Log message.
Definition: GwLogMessage.h:94
static void SetLogParameters(short global_debug_level=0, short max_indent=5, short max_before_clear=7)
to modify the global parameters
static void SetDebug(short global_debug_level=0)
virtual unsigned int GetPID() const
To get the Process ID number.
Definition: GwLogMessage.h:208
virtual std::string Message() const
To get the current message.
Definition: GwLogMessage.h:281
virtual ~LogMessage()
should purge the message
virtual void ClearMessage()
To clear the current message.
LogMessage(const char *pname, unsigned int pid=0u)
LogMessage & info(LogMessage &)
manipulator to modify the LogMessage
virtual void SetProcessPtr(void *address)
To set the Process address.
Definition: GwLogMessage.h:220
virtual void Send()
To send the message to the log collector.
virtual std::string Footer() const
To get the Footer of the current message.
Definition: GwLogMessage.h:290
LogMessage & dolog(LogMessage &)
bool IsDebug(short debug_to_test) const
to test if the required debug level is lower that the global one
Definition: GwLogMessage.h:184
LogMessage & debug(LogMessage &)
virtual void Indent()
to format the output string ... increase indent level
LogMessage & clear(LogMessage &)
others
virtual void SetVerboseLevel(unsigned short verbosity)
To get the current level of the message.
Definition: GwLogMessage.h:272
virtual std::string & GetProcessName()
To get the Process name.
Definition: GwLogMessage.h:224
virtual ELevel GetLevel() const
To get the current level of the message.
Definition: GwLogMessage.h:266
virtual LogMessage & operator<<(LogMessage &(*pf)(LogMessage &))
To allow manipulators.
Definition: GwLogMessage.h:294
ELevel
message level
Definition: GwLogMessage.h:109
virtual std::ostringstream & operator()()
Allow to pass the underlying stream to funtions/methods.
Definition: GwLogMessage.h:204
virtual void SetProcessMethod(const char *)
To set the current method.
virtual std::string & GetProcessMethod()
To get the current method.
Definition: GwLogMessage.h:227
virtual std::string Header() const
To get the header of the current message.
Definition: GwLogMessage.h:287
virtual void DoClear()
really clear the message
virtual void SetLevel(ELevel lev, unsigned short verbosity=0u)
To get the current level of the message.
virtual ELevel GetLowestLevel() const
To get the current level of the message.
Definition: GwLogMessage.h:269
LogMessage & operator<<(T t)
send any request to the underlying ostringstream
Definition: GwLogMessage.h:298