]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliLog.h
Increase class version (forgotten in the previous commit)
[u/mrichter/AliRoot.git] / STEER / AliLog.h
index 960e818f50269d212f41cd089656cf4046cc6919..64e041c494537284e4bf2518f5a61b76f236575f 100644 (file)
@@ -20,10 +20,12 @@ class AliLog: public TObject {
   virtual ~AliLog();
   static AliLog* Instance() {return fgInstance;}
 
-  enum EType {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType};
+  enum EType_t {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType};
+  typedef void (*AliLogNotification)(EType_t type, const char* message );
+
 
   static void  EnableDebug(Bool_t enabled);
-  static void  SetGlobalLogLevel(EType type);
+  static void  SetGlobalLogLevel(EType_t type);
   static Int_t GetGlobalLogLevel();
   static void  SetGlobalDebugLevel(Int_t level);
   static Int_t GetGlobalDebugLevel();
@@ -33,27 +35,31 @@ class AliLog: public TObject {
   static void  ClearClassDebugLevel(const char* className);
 
   static void  SetStandardOutput();
-  static void  SetStandardOutput(EType type);
+  static void  SetStandardOutput(EType_t type);
   static void  SetErrorOutput();
-  static void  SetErrorOutput(EType type);
+  static void  SetErrorOutput(EType_t type);
   static void  SetFileOutput(const char* fileName);
-  static void  SetFileOutput(EType type, const char* fileName);
+  static void  SetFileOutput(EType_t type, const char* fileName);
+  static void  SetStreamOutput(ostream* stream);
+  static void  SetStreamOutput(EType_t type, ostream* stream);
+  static void  SetLogNotification(AliLogNotification pCallBack);
+  static void  SetLogNotification(EType_t type, AliLogNotification pCallBack);
   static void  Flush();
 
   static void  SetHandleRootMessages(Bool_t on);
 
   static void  SetPrintType(Bool_t on);
-  static void  SetPrintType(EType type, Bool_t on);
+  static void  SetPrintType(EType_t type, Bool_t on);
   static void  SetPrintModule(Bool_t on);
-  static void  SetPrintModule(EType type, Bool_t on);
+  static void  SetPrintModule(EType_t type, Bool_t on);
   static void  SetPrintScope(Bool_t on);
-  static void  SetPrintScope(EType type, Bool_t on);
+  static void  SetPrintScope(EType_t type, Bool_t on);
   static void  SetPrintLocation(Bool_t on);
-  static void  SetPrintLocation(EType type, Bool_t on);
+  static void  SetPrintLocation(EType_t type, Bool_t on);
 
   static void  SetPrintRepetitions(Bool_t on);
 
-  static void  Write(const char* name, Int_t option = 0);
+  static void  WriteToFile(const char* name, Int_t option = 0);
 
   // the following public methods are used by the preprocessor macros 
   // and should not be called directly
@@ -66,16 +72,16 @@ class AliLog: public TObject {
                      const char* module, const char* className,
                      const char* function, const char* file, Int_t line);
 
-  static Int_t RedirectStdoutTo(EType type, UInt_t level, const char* module, 
+  static Int_t RedirectStdoutTo(EType_t type, UInt_t level, const char* module, 
                                 const char* className, const char* function,
                                 const char* file, Int_t line, Bool_t print);
-  static Int_t RedirectStderrTo(EType type, UInt_t level, const char* module, 
+  static Int_t RedirectStderrTo(EType_t type, UInt_t level, const char* module, 
                                 const char* className, const char* function,
                                 const char* file, Int_t line, Bool_t print);
   static void  RestoreStdout(Int_t original);
   static void  RestoreStderr(Int_t original);
 
-  static ostream& Stream(EType type, UInt_t level,
+  static ostream& Stream(EType_t type, UInt_t level,
                          const char* module, const char* className,
                          const char* function, const char* file, Int_t line);
 
@@ -96,14 +102,16 @@ class AliLog: public TObject {
                               const char* module, const char* className,
                               const char* function, 
                               const char* file, Int_t line);
+
+  void           PrintString(Int_t type, FILE* stream, const char* format, ...);
   void           PrintRepetitions();
 
-  Int_t          RedirectTo(FILE* stream, EType type, UInt_t level,
+  Int_t          RedirectTo(FILE* stream, EType_t type, UInt_t level,
                             const char* module, const char* className,
                             const char* function,
                             const char* file, Int_t line, Bool_t print);
 
-  ostream&       GetStream(EType type, UInt_t level,
+  ostream&       GetStream(EType_t type, UInt_t level,
                            const char* module, const char* className,
                            const char* function, const char* file, Int_t line);
 
@@ -120,7 +128,7 @@ class AliLog: public TObject {
   Int_t          fOutputTypes[kMaxType];     // types of output streams
   TString        fFileNames[kMaxType];       // file names
   FILE*          fOutputFiles[kMaxType];     //! log output files
-  ofstream*      fOutputStreams[kMaxType];   //! log output streams
+  ostream*       fOutputStreams[kMaxType];   //! log output streams
 
   Bool_t         fPrintType[kMaxType];       // print type on/off
   Bool_t         fPrintModule[kMaxType];     // print module on/off
@@ -137,14 +145,15 @@ class AliLog: public TObject {
   TString        fLastFunction;              //! function name of last message
   TString        fLastFile;                  //! file name of last message
   Int_t          fLastLine;                  //! line number of last message
+  AliLogNotification fCallBacks[kMaxType];   //! external notification callback
 
   ClassDef(AliLog, 1)   // class for logging debug, info and error messages
 };
 
 
 // module name
-#ifdef __MODULE__
-#define MODULENAME() __MODULE__
+#ifdef _MODULE_
+#define MODULENAME() _MODULE_
 #else
 #define MODULENAME() "NoModule"
 #endif
@@ -181,9 +190,44 @@ class AliLog: public TObject {
 #define AliDebugClass(level, message)
 #define AliDebugGeneral(scope, level, message)
 #else
-#define AliDebug(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);}
-#define AliDebugClass(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);}
-#define AliDebugGeneral(scope, level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);}
+/** @defn AliDebug 
+    @param N Debug level - always evaluated 
+    @param A Argument Form(including paranthesis) - the message to
+    print.  Note, that @a A should contain balanced paranthesis, like 
+    @verbatim 
+      AliDebug(1, Form("Failed to decode line %d of %s", line, filename));
+    @endverbatim 
+    The point is, if the current log level isn't high enough, as
+    returned by the AliLog object, then we do not want to evalute the
+    call to Form, since that is an expensive call.  We should always
+    put macros like this into a @c do ... @c while loop, since that
+    makes sure that evaluations are local, and that we can safely put
+    a @c ; after the macro call.  Note, that @c do ... @c while loop
+    and the call with extra paranthis, are an old tricks used by many
+    C coders (see for example Bison, the Linux kernel, and the like).
+    Christian Holm Christensen
+*/
+#define AliDebug(N, A) \
+  do { \
+    if (!AliLog::IsDebugEnabled() || \
+      AliLog::GetDebugLevel(MODULENAME(), ClassName()) < N)  break; \
+    AliLog::Debug(N, A, MODULENAME(), ClassName(), FUNCTIONNAME(), \
+                 __FILE__, __LINE__); } while (false)
+//#define AliDebug(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), ClassName(), FUNCTIONNAME(), __FILE__, __LINE__);}
+#define AliDebugClass(N, A) \
+  do { \
+    if (!AliLog::IsDebugEnabled() || \
+      AliLog::GetDebugLevel(MODULENAME(), Class()->GetName()) < N)  break; \
+    AliLog::Debug(N, A, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), \
+                 __FILE__, __LINE__); } while (false)
+//#define AliDebugClass(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__);}
+#define AliDebugGeneral(scope, N, A) \
+  do { \
+    if (!AliLog::IsDebugEnabled() || \
+      AliLog::GetDebugLevel(MODULENAME(), scope) < N)  break; \
+    AliLog::Debug(N, A, MODULENAME(), scope, FUNCTIONNAME(), \
+                 __FILE__, __LINE__); } while (false)
+//#define AliDebugGeneral(scope, level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__);}
 #endif
 
 // redirection to debug