36 #include <Riostream.h> 65 Bool_t
AliLog::fgDebugEnabled = kTRUE;
66 Bool_t
AliLog::fgCoreEnabled = kFALSE;
73 if (fgInstance == NULL)
192 Fatal(
"AliLog",
"copy constructor not implemented");
201 Fatal(
"operator =",
"assignment operator not implemented");
220 static const char* typeNames[
kMaxType] = {
"kFatal",
"kError",
"kWarning",
"kInfo",
"kDebug"};
223 if (gSystem->Getenv(
"LOG_NO_DEBUG"))
227 else if (gEnv->Defined(
"AliRoot.AliLog.EnableDebug"))
234 if (gEnv->Defined(
"AliRoot.AliLog.GlobalLogLevel"))
236 const char* type = gEnv->GetValue(
"AliRoot.AliLog.GlobalLogLevel",
"");
247 if (gEnv->Defined(
"AliRoot.AliLog.GlobalDebugLevel"))
256 if (gEnv->Defined(
"AliRoot.AliLog.ModuleDebugLevel"))
258 TString levels = gEnv->GetValue(
"AliRoot.AliLog.ModuleDebugLevel",
"");
259 char*
p =
const_cast<char*
>(levels.Data());
261 while (
const char* module = strtok(p,
" "))
264 char* pos =
const_cast<char*
>(index(module,
':'));
267 Int_t level = atoi(pos);
269 AliDebug(3, Form(
"debug level for module %s set to %d", module, level));
274 if (gEnv->Defined(
"AliRoot.AliLog.ClassDebugLevel"))
276 TString levels = gEnv->GetValue(
"AliRoot.AliLog.ClassDebugLevel",
"");
277 char*
p =
const_cast<char*
>(levels.Data());
279 while (
const char* className = strtok(p,
" "))
282 char* pos =
const_cast<char*
>(index(className,
':'));
285 Int_t level = atoi(pos);
287 AliDebug(3, Form(
"debug level for class %s set to %d", className, level));
292 if (gEnv->Defined(
"AliRoot.AliLog.Output"))
294 TString stream = gEnv->GetValue(
"AliRoot.AliLog.Output",
"Standard");
296 if (stream.CompareTo(
"standard", TString::kIgnoreCase) == 0)
299 AliDebug(3,
"output stream set to standard output for all types");
301 else if (stream.CompareTo(
"error", TString::kIgnoreCase) == 0)
304 AliDebug(3,
"output stream set to error output for all types");
306 else if (!stream.IsNull())
309 AliDebug(3, Form(
"output stream set to file %s for all types", stream.Data()));
316 TString name(
"AliRoot.AliLog.Output.");
317 name += &typeNames[iType][1];
319 if (gEnv->Defined(name))
321 TString stream = gEnv->GetValue(name,
"Standard");
323 if (stream.CompareTo(
"standard", TString::kIgnoreCase) == 0)
326 AliDebug(3, Form(
"output stream set to standard output for type %s", typeNames[iType]));
328 else if (stream.CompareTo(
"error", TString::kIgnoreCase) == 0)
331 AliDebug(3, Form(
"output stream set to error output for type %s", typeNames[iType]));
333 else if (!stream.IsNull())
336 AliDebug(3, Form(
"output stream set to file %s for type %s", stream.Data(), typeNames[iType]));
342 if (gEnv->Defined(
"AliRoot.AliLog.HandleRootMessages"))
344 Bool_t on = gEnv->GetValue(
"AliRoot.AliLog.HandleRootMessages", kTRUE);
346 AliDebug(3, Form(
"handling of root messages %sabled", ((on) ?
"en" :
"dis")));
350 static const char* settingNames[4] = {
"Type",
"Module",
"Scope",
"Location"};
353 for (Int_t iSetting = 0; iSetting < 4; iSetting++)
355 TString name(
"AliRoot.AliLog.Print");
356 name += settingNames[iSetting];
358 if (gEnv->Defined(name))
360 Bool_t on = gEnv->GetValue(name, settings[iSetting][0]);
364 settings[iSetting][iType] = on;
366 AliDebug(3, Form(
"printing of %s %sabled for all types", settingNames[iSetting], ((on) ?
"en" :
"dis")));
371 TString nameType = name +
"." + &typeNames[iType][1];
373 if (gEnv->Defined(nameType))
375 Bool_t on = gEnv->GetValue(nameType, settings[iSetting][iType]);
376 settings[iSetting][iType] = on;
377 AliDebug(3, Form(
"printing of %s %sabled for type %s", settingNames[iSetting], ((on) ?
"en" :
"dis"), typeNames[iType]));
383 if (gEnv->Defined(
"AliRoot.AliLog.PrintRepetitions"))
385 Bool_t on = gEnv->GetValue(
"AliRoot.AliLog.PrintRepetitions", kTRUE);
387 AliDebug(3, Form(
"printing of message repetitions %sabled", ((on) ?
"en" :
"dis")));
389 if (gSystem->Getenv(
"ALIROOT_FORCE_COREDUMP")){
398 const char* location,
const char* message)
404 case ::kFatal : level =
kFatal;
break;
406 DefaultErrorHandler(level, abort, location, message);
409 DefaultErrorHandler(level, abort, location, message);
411 case ::kError : level =
kError;
break;
412 case ::kWarning : level =
kWarning;
break;
413 case ::kInfo : level =
kInfo;
break;
414 default : level =
kDebug;
break;
432 gSystem->Exec(
"ulimit -c unlimited");
434 gSystem->ResetSignal(kSigFloatingException,enabled);
435 gSystem->ResetSignal(kSigSegmentationViolation,enabled);
437 printf(
"Core dump enabled\n");
440 printf(
"Core dump disabled\n");
493 obj =
new TNamed(module, module);
498 obj->SetUniqueID(level);
517 if (!className)
return;
521 obj =
new TNamed(className, className);
526 obj->SetUniqueID(level);
534 if (!className)
return;
628 Bool_t closeFile = kTRUE;
636 ofstream* stream=
reinterpret_cast<ofstream*
>(
fOutputStreams[type]);
658 ostream* stream = NULL;
661 if ((iType != type) &&
671 stream =
new ofstream(
fFileNames[type], ios::app);
710 SetErrorHandler(DefaultErrorHandler);
833 if (obj)
return obj->GetUniqueID();
837 if (obj)
return obj->GetUniqueID();
853 const char* module,
const char* className,
854 const char*
function,
const char* file, Int_t line)
862 ((module && (
fLastModule.CompareTo(module) == 0)) ||
868 ((file && (
fLastFile.CompareTo(file) == 0)) ||
890 static const char* typeNames[
kMaxType] =
891 {
"Fatal",
"Error",
"Warning",
"Info",
"Debug"};
894 PrintString(type, stream,
"%c-", typeNames[type][0]);
903 PrintString(type, stream,
"%s: %s",
function, message);
908 PrintString(type, stream,
" (%s:%.0d)", file, line);
930 const char* module,
const char* className,
931 const char*
function,
const char* file, Int_t line)
942 if (level <= fgInstance->
GetLogLevel(module, className)) {
944 module, className,
function, file, line);
950 module, className,
function, file, line);
953 gSystem->StackTrace();
967 const char* module,
const char* className,
968 const char*
function,
const char* file, Int_t line)
972 if (level == 0) level = 1;
974 Message(level, message, module, className,
function, file, line);
980 const char* className,
const char*
function,
981 const char* file, Int_t line, Bool_t print)
987 function, file, line, print);
992 const char* className,
const char*
function,
993 const char* file, Int_t line, Bool_t print)
999 function, file, line, print);
1004 const char* module,
const char* className,
1005 const char*
function,
const char* file, Int_t line,
1011 Int_t original = dup(fileno(stream));
1019 if ((type ==
kDebug) && (level > 0)) level--;
1020 if (type + level >
GetLogLevel(module, className)) {
1021 if(!freopen(
"/dev/null",
"a", stream))
AliWarning(
"Cannot reopen /dev/null");
1023 if (stream != stdout) dup2(fileno(stdout), fileno(stream));
1025 if (stream != stderr) dup2(fileno(stderr), fileno(stream));
1034 PrintMessage(type, NULL, module, className,
function, file, line);
1047 dup2(original, fileno(stdout));
1057 dup2(original, fileno(stderr));
1064 const char* module,
const char* className,
1065 const char*
function,
const char* file, Int_t line)
1071 function, file, line);
1076 const char* module,
const char* className,
1077 const char*
function,
const char* file, Int_t line)
1081 if ((type ==
kDebug) && (level > 0)) level--;
1082 Bool_t noOutput = (type + level >
GetLogLevel(module, className));
1085 PrintMessage(type, NULL, module, className,
function, file, line);
1089 static ofstream nullStream(
"/dev/null");
1163 if (format==NULL)
return;
1166 va_start(ap, format);
1169 vfprintf(stream, format, ap);
1173 TString fmt(format);
1174 TArrayC tgt(fmt.Length()*10);
1177 R__VA_COPY(bap, ap);
1179 #warning definition of R__VA_COPY has disappeared 1184 iResult=vsnprintf(tgt.GetArray(), tgt.GetSize(), format, ap);
1186 iResult=tgt.GetSize()*2;
1187 }
else if (iResult<tgt.GetSize()) {
1191 if (iResult<10000) {
1194 R__VA_COPY(ap, bap);
1198 tgt[tgt.GetSize()-1]=0;
1230 if (!gSystem)
return;
1231 printf(
"AliLog::MakeCoreDump\n");
1233 gSystem->Exec(Form(
"gcore -o %s %d",fout, gSystem->GetPid()));
1235 gSystem->Exec(Form(
"gcore %d", gSystem->GetPid()));
1244 printf(
"AliLog::TestException(%d)\n",level);
1249 throw std::runtime_error(
"Test exception");
AliLogNotification fCallBacks[kMaxType]
line number of last message
TString fLastMessage
type of last message
static void ClearModuleDebugLevel(const char *module)
FILE * fOutputFiles[kMaxType]
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void(* AliLogNotification)(EType_t type, const char *message)
void PrintString(Int_t type, FILE *stream, const char *format,...)
static void MakeCoreDump(const char *fout)
static void SetGlobalLogLevel(EType_t type)
TObjArray fClassDebugLevels
static void SetClassDebugLevel(const char *className, Int_t level)
static void RestoreStdout(Int_t original)
FILE * GetOutputStream(Int_t type)
static void RootErrorHandler(Int_t level, Bool_t abort, const char *location, const char *message)
Bool_t fPrintLocation[kMaxType]
static void Message(UInt_t level, const char *message, const char *module, const char *className, const char *function, const char *file, Int_t line)
static void SetFileOutput(const char *fileName)
Int_t fOutputTypes[kMaxType]
static void SetStreamOutput(ostream *stream)
static Bool_t fgDebugEnabled
pointer to current instance
static void SetHandleRootMessages(Bool_t on)
TString fLastFunction
class name of last message
UInt_t fLastType
counter of repetitions
TString fileName(const char *dir, int runNumber, const char *da, int i, const char *type)
#define AliWarning(message)
static Bool_t fgCoreEnabled
ostream & GetStream(EType_t type, UInt_t level, const char *module, const char *className, const char *function, const char *file, Int_t line)
static void TestException(Int_t level=10)
static ostream & Stream(EType_t type, UInt_t level, const char *module, const char *className, const char *function, const char *file, Int_t line)
static AliLog * fgInstance
static void SetLogNotification(AliLogNotification pCallBack)
static Int_t GetGlobalDebugLevel()
static void WriteToFile(const char *name, Int_t option=0)
AliLog & operator=(const AliLog &log)
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)
Bool_t fPrintType[kMaxType]
log output streams
TString fLastFile
function name of last message
Bool_t fPrintModule[kMaxType]
static void SetModuleDebugLevel(const char *module, Int_t level)
static void SetPrintModule(Bool_t on)
static void SetPrintType(Bool_t on)
static void EnableDebug(Bool_t enabled)
#define AliDebug(logLevel, message)
TString fLastModule
last message
static void SetGlobalDebugLevel(Int_t level)
static void Debug(UInt_t level, const char *message, const char *module, const char *className, const char *function, const char *file, Int_t line)
TString fLastClassName
module name of last message
static void SetPrintRepetitions(Bool_t on)
static void SetPrintScope(Bool_t on)
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 GetDebugLevel(const char *module, const char *className)
void PrintMessage(UInt_t type, const char *message, const char *module, const char *className, const char *function, const char *file, Int_t line)
Int_t fLastLine
file name of last message
ostream * fOutputStreams[kMaxType]
log output files
static void ClearClassDebugLevel(const char *className)
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)
static Int_t GetGlobalLogLevel()
UInt_t GetLogLevel(const char *module, const char *className) const
TString fFileNames[kMaxType]
static void SetStandardOutput()
static void SetPrintLocation(Bool_t on)
void CloseFile(Int_t type)
static void DeleteRootLogger()
static void EnableCoreDump(Bool_t enabled)
static void RestoreStderr(Int_t original)
static void SetErrorOutput()
Bool_t fPrintScope[kMaxType]
TObjArray fModuleDebugLevels