Resolving platform dependence in the definition of __FUNCTION__
[u/mrichter/AliRoot.git] / STEER / AliLog.h
CommitLineData
6ab674bd 1#ifndef ALILOG_H
2#define ALILOG_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
6/* $Id$ */
7
8///
9/// class for logging debug, info and error messages
10///
11
12#include <TObject.h>
13#include <TObjArray.h>
14#include <TString.h>
15
16
17class AliLog: public TObject {
18 public:
19 AliLog();
20 virtual ~AliLog();
21 static AliLog* Instance() {return fgInstance;}
22
23 enum EType {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType};
24
25 static void EnableDebug(Bool_t enabled);
26 static void SetGlobalLogLevel(EType type);
27 static Int_t GetGlobalLogLevel();
28 static void SetGlobalDebugLevel(Int_t level);
29 static Int_t GetGlobalDebugLevel();
30 static void SetModuleDebugLevel(const char* module, Int_t level);
31 static void ClearModuleDebugLevel(const char* module);
32 static void SetClassDebugLevel(const char* className, Int_t level);
33 static void ClearClassDebugLevel(const char* className);
34
35 static void SetStandardOutput();
36 static void SetStandardOutput(EType type);
37 static void SetErrorOutput();
38 static void SetErrorOutput(EType type);
39 static void SetFileOutput(const char* fileName);
40 static void SetFileOutput(EType type, const char* fileName);
41 static void Flush();
42
43 static void SetHandleRootMessages(Bool_t on);
44
45 static void SetPrintType(Bool_t on);
46 static void SetPrintType(EType type, Bool_t on);
47 static void SetPrintModule(Bool_t on);
48 static void SetPrintModule(EType type, Bool_t on);
49 static void SetPrintScope(Bool_t on);
50 static void SetPrintScope(EType type, Bool_t on);
51 static void SetPrintLocation(Bool_t on);
52 static void SetPrintLocation(EType type, Bool_t on);
53
54 static void Write(const char* name, Int_t option = 0);
55
56 // the following public methods are used by the preprocessor macros
57 // and should not be called directly
20848f77 58 static Bool_t IsDebugEnabled() {return fgDebugEnabled;}
6ab674bd 59 static Int_t GetDebugLevel(const char* module, const char* className);
60 static void Message(UInt_t level, const char* message,
61 const char* module, const char* className,
62 const char* function, const char* file, Int_t line);
63 static void Debug(UInt_t level, const char* message,
64 const char* module, const char* className,
65 const char* function, const char* file, Int_t line);
66
67 private:
68 AliLog(const AliLog& log);
69 AliLog& operator = (const AliLog& log);
70
71 static void RootErrorHandler(Int_t level, Bool_t abort,
72 const char* location, const char* message);
73
74 void CloseFile(Int_t type);
75 FILE* GetOutputStream(Int_t type);
76
77 UInt_t GetLogLevel(const char* module, const char* className) const;
78
79 enum {kDebugOffset = kDebug-1};
80
81 static AliLog* fgInstance; //! pointer to current instance
82
83 static Bool_t fgDebugEnabled; // flag for debug en-/disabling
84
85 UInt_t fGlobalLogLevel; // global logging level
86 TObjArray fModuleDebugLevels; // debug levels for modules
87 TObjArray fClassDebugLevels; // debug levels for classes
88
89 Int_t fOutputTypes[kMaxType]; // types of output streams
90 TString fFileNames[kMaxType]; // file names
91 FILE* fOutputFiles[kMaxType]; //! log output files
92
93 Bool_t fPrintType[kMaxType]; // print type on/off
94 Bool_t fPrintModule[kMaxType]; // print module on/off
95 Bool_t fPrintScope[kMaxType]; // print scope/class name on/off
96 Bool_t fPrintLocation[kMaxType]; // print file and line on/off
97
98 ClassDef(AliLog, 1) // class for logging debug, info and error messages
99};
100
cd676389 101#ifndef __GNUC__
102#ifndef __APPLE__
103#define __FUNCTION__ "???"
104#endif
105#endif
6ab674bd 106
107#ifdef LOG_NO_DEBUG
108#define AliDebugLevel() -1
109#define AliDebugLevelClass() -1
110#define AliDebugLevelGeneral(scope) -1
111#else
20848f77 112#define AliDebugLevel() ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(__MODULE__, ClassName()) : -1)
113#define AliDebugLevelClass() ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(__MODULE__, Class()->GetName()) : -1)
114#define AliDebugLevelGeneral(scope) ((AliLog::IsDebugEnabled()) ? AliLog::GetDebugLevel(__MODULE__, scope) : -1)
6ab674bd 115#endif
116
117#ifdef LOG_NO_DEBUG
118#define AliDebug(level, message)
119#define AliDebugClass(level, message)
120#define AliDebugGeneral(scope, level, message)
121#else
20848f77 122#define AliDebug(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, __MODULE__, ClassName(), __FUNCTION__, __FILE__, __LINE__);}
123#define AliDebugClass(level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, __MODULE__, Class()->GetName(), __FUNCTION__, __FILE__, __LINE__);}
124#define AliDebugGeneral(scope, level, message) {if (AliLog::IsDebugEnabled()) AliLog::Debug(level, message, __MODULE__, scope, __FUNCTION__, __FILE__, __LINE__);}
6ab674bd 125#endif
126
127#ifdef LOG_NO_INFO
128#define AliInfo(message)
129#define AliInfoClass(message)
130#define AliInfoGeneral(scope, message)
131#else
132#define AliInfo(message) {AliLog::Message(AliLog::kInfo, message, __MODULE__, ClassName(), __FUNCTION__, __FILE__, __LINE__);}
133#define AliInfoClass(message) {AliLog::Message(AliLog::kInfo, message, __MODULE__, Class()->GetName(), __FUNCTION__, __FILE__, __LINE__);}
134#define AliInfoGeneral(scope, message) {AliLog::Message(AliLog::kInfo, message, __MODULE__, scope, __FUNCTION__, __FILE__, __LINE__);}
135#endif
136
137#ifdef LOG_NO_WARNING
138#define AliWarning(message)
139#define AliWarningClass(message)
140#define AliWarningGeneral(scope, message)
141#else
142#define AliWarning(message) {AliLog::Message(AliLog::kWarning, message, __MODULE__, ClassName(), __FUNCTION__, __FILE__, __LINE__);}
143#define AliWarningClass(message) {AliLog::Message(AliLog::kWarning, message, __MODULE__, Class()->GetName(), __FUNCTION__, __FILE__, __LINE__);}
144#define AliWarningGeneral(scope, message) {AliLog::Message(AliLog::kWarning, message, __MODULE__, scope, __FUNCTION__, __FILE__, __LINE__);}
145#endif
146
147#define AliError(message) {AliLog::Message(AliLog::kError, message, __MODULE__, ClassName(), __FUNCTION__, __FILE__, __LINE__);}
148#define AliErrorClass(message) {AliLog::Message(AliLog::kError, message, __MODULE__, Class()->GetName(), __FUNCTION__, __FILE__, __LINE__);}
149#define AliErrorGeneral(scope, message) {AliLog::Message(AliLog::kError, message, __MODULE__, scope, __FUNCTION__, __FILE__, __LINE__);}
150
151#define AliFatal(message) {AliLog::Message(AliLog::kFatal, message, __MODULE__, ClassName(), __FUNCTION__, __FILE__, __LINE__);}
152#define AliFatalClass(message) {AliLog::Message(AliLog::kFatal, message, __MODULE__, Class()->GetName(), __FUNCTION__, __FILE__, __LINE__);}
153#define AliFatalGeneral(scope, message) {AliLog::Message(AliLog::kFatal, message, __MODULE__, scope, __FUNCTION__, __FILE__, __LINE__);}
154
155#endif