1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////////
20 // class for logging debug, info and error messages //
22 // The AliLog class is a singleton class. It allows to steer the output //
23 // level and output streams for different types of messages via static //
26 // It also handles the messages produces by the preprocessor macros defined //
27 // in the header file: AliDebug, AliInfo, AliWarning, AliError, AliFatal. //
29 // More details about the message logging can be found on the ALICE Offline //
32 ///////////////////////////////////////////////////////////////////////////////
35 #include <Riostream.h>
46 AliLog* AliLog::fgInstance = NULL;
48 Bool_t AliLog::fgDebugEnabled = kTRUE;
51 //_____________________________________________________________________________
54 fGlobalLogLevel(kInfo),
57 fPrintRepetitions(kTRUE),
67 // default constructor: set default values
69 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
70 fOutputTypes[iType] = 0;
71 fFileNames[iType] = "";
72 fOutputFiles[iType] = NULL;
73 fOutputStreams[iType] = NULL;
75 fPrintType[iType] = kTRUE;
76 fPrintModule[iType] = kFALSE;
77 fPrintScope[iType] = kTRUE;
78 fPrintLocation[iType] = (iType == kDebug);
81 // replace the previous instance by this one
82 if (fgInstance) delete fgInstance;
85 SetHandleRootMessages(kTRUE);
87 // read the .rootrc settings
91 //_____________________________________________________________________________
94 // destructor: clean up and reset instance pointer
96 if (fRepetitions > 0) PrintRepetitions();
98 for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++) {
99 if (fModuleDebugLevels[i]) fModuleDebugLevels[i]->Delete();
101 fClassDebugLevels.Delete();
102 for (Int_t i = 0; i < fClassDebugLevels.GetEntriesFast(); i++) {
103 if (fClassDebugLevels[i]) fClassDebugLevels[i]->Delete();
105 fClassDebugLevels.Delete();
107 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
116 //_____________________________________________________________________________
117 AliLog::AliLog(const AliLog& log) :
119 fGlobalLogLevel(log.fGlobalLogLevel),
120 fModuleDebugLevels(log.fModuleDebugLevels),
121 fClassDebugLevels(log.fClassDebugLevels),
122 fPrintRepetitions(log.fPrintRepetitions),
123 fRepetitions(log.fRepetitions),
124 fLastType(log.fLastType),
125 fLastMessage(log.fLastMessage),
126 fLastModule(log.fLastModule),
127 fLastClassName(log.fLastClassName),
128 fLastFunction(log.fLastFunction),
129 fLastFile(log.fLastFile),
130 fLastLine(log.fLastLine)
134 Fatal("AliLog", "copy constructor not implemented");
137 //_____________________________________________________________________________
138 AliLog& AliLog::operator = (const AliLog& /*log*/)
140 // assignment operator
142 Fatal("operator =", "assignment operator not implemented");
147 //_____________________________________________________________________________
148 void AliLog::ReadEnvSettings()
150 // load settings from the root configuration file (.rootrc)
151 // and from environment variables
153 static const char* typeNames[kMaxType] =
154 {"kFatal", "kError", "kWarning", "kInfo", "kDebug"};
156 // debug en- or disabling
157 if (gSystem->Getenv("LOG_NO_DEBUG")) {
158 fgDebugEnabled = kFALSE;
159 } else if (gEnv->Defined("AliRoot.AliLog.EnableDebug")) {
160 fgDebugEnabled = gEnv->GetValue("AliRoot.AliLog.EnableDebug",
162 AliInfo(Form("debug %sabled", ((fgDebugEnabled) ? "en" : "dis")));
166 if (gEnv->Defined("AliRoot.AliLog.GlobalLogLevel")) {
167 const char* type = gEnv->GetValue("AliRoot.AliLog.GlobalLogLevel", "");
168 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
169 if (strcmp(type, typeNames[iType]) == 0) fGlobalLogLevel = iType;
171 AliDebug(3, Form("global log level set to %d", fGlobalLogLevel));
174 // global debug level
175 if (gEnv->Defined("AliRoot.AliLog.GlobalDebugLevel")) {
176 Int_t level = gEnv->GetValue("AliRoot.AliLog.GlobalDebugLevel",
177 Int_t(fGlobalLogLevel - kDebugOffset));
178 if (level < -kDebugOffset) level = kDebugOffset;
179 fGlobalLogLevel = kDebugOffset + level;
180 AliDebug(3, Form("global debug level set to %d",
181 fGlobalLogLevel - kDebugOffset));
184 // module debug level
185 if (gEnv->Defined("AliRoot.AliLog.ModuleDebugLevel")) {
186 TString levels = gEnv->GetValue("AliRoot.AliLog.ModuleDebugLevel", "");
187 char* p = const_cast<char*>(levels.Data());
188 while (const char* module = strtok(p, " ")) {
190 char* pos = index(module, ':');
193 Int_t level = atoi(pos);
194 SetModuleDebugLevel(module, level);
195 AliDebug(3, Form("debug level for module %s set to %d", module, level));
200 if (gEnv->Defined("AliRoot.AliLog.ClassDebugLevel")) {
201 TString levels = gEnv->GetValue("AliRoot.AliLog.ClassDebugLevel", "");
202 char* p = const_cast<char*>(levels.Data());
203 while (const char* className = strtok(p, " ")) {
205 char* pos = index(className, ':');
208 Int_t level = atoi(pos);
209 SetClassDebugLevel(className, level);
210 AliDebug(3, Form("debug level for class %s set to %d",
215 // general output stream
216 if (gEnv->Defined("AliRoot.AliLog.Output")) {
217 TString stream = gEnv->GetValue("AliRoot.AliLog.Output", "Standard");
218 if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
220 AliDebug(3, "output stream set to standard output for all types");
221 } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
223 AliDebug(3, "output stream set to error output for all types");
224 } else if (!stream.IsNull()) {
225 SetFileOutput(stream);
226 AliDebug(3, Form("output stream set to file %s for all types",
231 // individual output streams
232 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
233 TString name("AliRoot.AliLog.Output.");
234 name += &typeNames[iType][1];
235 if (gEnv->Defined(name)) {
236 TString stream = gEnv->GetValue(name, "Standard");
237 if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
238 SetStandardOutput(EType(iType));
239 AliDebug(3, Form("output stream set to standard output for type %s",
241 } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
242 SetErrorOutput(EType(iType));
243 AliDebug(3, Form("output stream set to error output for type %s",
245 } else if (!stream.IsNull()) {
246 SetFileOutput(EType(iType), stream);
247 AliDebug(3, Form("output stream set to file %s for type %s",
248 stream.Data(), typeNames[iType]));
253 // handling of root error messages
254 if (gEnv->Defined("AliRoot.AliLog.HandleRootMessages")) {
255 Bool_t on = gEnv->GetValue("AliRoot.AliLog.HandleRootMessages", kTRUE);
256 SetHandleRootMessages(on);
257 AliDebug(3, Form("handling of root messages %sabled",
258 ((on) ? "en" : "dis")));
262 static const char* settingNames[4] =
263 {"Type", "Module", "Scope", "Location"};
265 {fPrintType, fPrintModule, fPrintScope, fPrintLocation};
266 for (Int_t iSetting = 0; iSetting < 4; iSetting++) {
267 TString name("AliRoot.AliLog.Print");
268 name += settingNames[iSetting];
269 if (gEnv->Defined(name)) {
270 Bool_t on = gEnv->GetValue(name, settings[iSetting][0]);
271 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
272 settings[iSetting][iType] = on;
274 AliDebug(3, Form("printing of %s %sabled for all types",
275 settingNames[iSetting], ((on) ? "en" : "dis")));
278 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
279 TString nameType = name + "." + &typeNames[iType][1];
280 if (gEnv->Defined(nameType)) {
281 Bool_t on = gEnv->GetValue(nameType, settings[iSetting][iType]);
282 settings[iSetting][iType] = on;
283 AliDebug(3, Form("printing of %s %sabled for type %s",
284 settingNames[iSetting], ((on) ? "en" : "dis"),
290 // repetition of messages
291 if (gEnv->Defined("AliRoot.AliLog.PrintRepetitions")) {
292 Bool_t on = gEnv->GetValue("AliRoot.AliLog.PrintRepetitions", kTRUE);
293 fPrintRepetitions = on;
294 AliDebug(3, Form("printing of message repetitions %sabled",
295 ((on) ? "en" : "dis")));
300 //_____________________________________________________________________________
301 void AliLog::RootErrorHandler(Int_t level, Bool_t abort,
302 const char* location, const char* message)
304 // new error handler for messages from root
307 case ::kFatal : level = kFatal; break;
309 DefaultErrorHandler(level, abort, location, message);
312 DefaultErrorHandler(level, abort, location, message);
314 case ::kError : level = kError; break;
315 case ::kWarning : level = kWarning; break;
316 case ::kInfo : level = kInfo; break;
317 default : level = kDebug; break;
319 AliLog::Message(level, message, "ROOT", NULL, location, NULL, 0);
323 //_____________________________________________________________________________
324 void AliLog::EnableDebug(Bool_t enabled)
326 // enable or disable debug output
328 fgDebugEnabled = enabled;
331 //_____________________________________________________________________________
332 void AliLog::SetGlobalLogLevel(EType type)
334 // set the global debug level
336 if (!fgInstance) new AliLog;
337 fgInstance->fGlobalLogLevel = type;
340 //_____________________________________________________________________________
341 Int_t AliLog::GetGlobalLogLevel()
343 // get the global debug level
345 if (!fgInstance) new AliLog;
346 return fgInstance->fGlobalLogLevel;
349 //_____________________________________________________________________________
350 void AliLog::SetGlobalDebugLevel(Int_t level)
352 // set the global debug level
354 if (!fgInstance) new AliLog;
355 if (level < -kDebugOffset) level = -kDebugOffset;
356 fgInstance->fGlobalLogLevel = kDebugOffset + level;
359 //_____________________________________________________________________________
360 Int_t AliLog::GetGlobalDebugLevel()
362 // get the global debug level
364 if (!fgInstance) new AliLog;
365 return fgInstance->fGlobalLogLevel - kDebugOffset;
368 //_____________________________________________________________________________
369 void AliLog::SetModuleDebugLevel(const char* module, Int_t level)
371 // set the debug level for the given module
374 if (!fgInstance) new AliLog;
375 TObject* obj = fgInstance->fModuleDebugLevels.FindObject(module);
377 obj = new TNamed(module, module);
378 fgInstance->fModuleDebugLevels.Add(obj);
380 level += kDebugOffset;
381 if (level < kFatal) level = kFatal;
382 obj->SetUniqueID(level);
385 //_____________________________________________________________________________
386 void AliLog::ClearModuleDebugLevel(const char* module)
388 // remove the setting of the debug level for the given module
391 if (!fgInstance) new AliLog;
392 TObject* obj = fgInstance->fModuleDebugLevels.FindObject(module);
393 if (obj) delete fgInstance->fModuleDebugLevels.Remove(obj);
396 //_____________________________________________________________________________
397 void AliLog::SetClassDebugLevel(const char* className, Int_t level)
399 // set the debug level for the given class
401 if (!className) return;
402 if (!fgInstance) new AliLog;
403 TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
405 obj = new TNamed(className, className);
406 fgInstance->fClassDebugLevels.Add(obj);
408 level += kDebugOffset;
409 if (level < kFatal) level = kFatal;
410 obj->SetUniqueID(level);
413 //_____________________________________________________________________________
414 void AliLog::ClearClassDebugLevel(const char* className)
416 // remove the setting of the debug level for the given class
418 if (!className) return;
419 if (!fgInstance) new AliLog;
420 TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
421 if (obj) delete fgInstance->fClassDebugLevels.Remove(obj);
425 //_____________________________________________________________________________
426 void AliLog::SetStandardOutput()
428 // write all log messages to the standard output (stdout)
430 if (!fgInstance) new AliLog;
431 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
432 fgInstance->CloseFile(iType);
433 fgInstance->fOutputTypes[iType] = 0;
437 //_____________________________________________________________________________
438 void AliLog::SetStandardOutput(EType type)
440 // write log messages of the given type to the standard output (stdout)
442 if ((type < kFatal) || (type >= kMaxType)) return;
443 if (!fgInstance) new AliLog;
444 fgInstance->CloseFile(type);
445 fgInstance->fOutputTypes[type] = 0;
448 //_____________________________________________________________________________
449 void AliLog::SetErrorOutput()
451 // write all log messages to the error output (stderr)
453 if (!fgInstance) new AliLog;
454 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
455 fgInstance->CloseFile(iType);
456 fgInstance->fOutputTypes[iType] = 1;
460 //_____________________________________________________________________________
461 void AliLog::SetErrorOutput(EType type)
463 // write log messages of the given type to the error output (stderr)
465 if ((type < kFatal) || (type >= kMaxType)) return;
466 if (!fgInstance) new AliLog;
467 fgInstance->CloseFile(type);
468 fgInstance->fOutputTypes[type] = 1;
471 //_____________________________________________________________________________
472 void AliLog::SetFileOutput(const char* fileName)
474 // write all log messages to the given file
476 if (!fgInstance) new AliLog;
477 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
478 if ((fgInstance->fOutputTypes[iType] == 2) &&
479 (fgInstance->fFileNames[iType].CompareTo(fileName) != 0)) {
480 fgInstance->CloseFile(iType);
482 fgInstance->fOutputTypes[iType] = 2;
483 fgInstance->fFileNames[iType] = fileName;
484 fgInstance->fOutputFiles[iType] = NULL;
485 fgInstance->fOutputStreams[iType] = NULL;
489 //_____________________________________________________________________________
490 void AliLog::SetFileOutput(EType type, const char* fileName)
492 // write log messages of the given type to the given file
494 if ((type < kFatal) || (type >= kMaxType)) return;
495 if (!fgInstance) new AliLog;
496 if ((fgInstance->fOutputTypes[type] == 2) &&
497 (fgInstance->fFileNames[type].CompareTo(fileName) != 0)) {
498 fgInstance->CloseFile(type);
500 fgInstance->fOutputTypes[type] = 2;
501 fgInstance->fFileNames[type] = fileName;
502 fgInstance->fOutputFiles[type] = NULL;
503 fgInstance->fOutputStreams[type] = NULL;
506 //_____________________________________________________________________________
507 void AliLog::CloseFile(Int_t type)
509 // close the file for the given type if needed
511 if ((fOutputTypes[type] == 2) && fOutputFiles[type]) {
512 Bool_t closeFile = kTRUE;
513 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
514 if ((iType != type) && (fOutputFiles[iType] == fOutputFiles[type])) {
519 fclose(fOutputFiles[type]);
520 fOutputStreams[type]->close();
521 delete fOutputStreams[type];
524 fOutputFiles[type] = NULL;
525 fOutputStreams[type] = NULL;
526 fFileNames[type] = "";
527 fOutputTypes[type] = 0;
530 //_____________________________________________________________________________
531 FILE* AliLog::GetOutputStream(Int_t type)
533 // get the output stream for the given type of messages
535 if (type > kDebug) type = kDebug;
536 if (fOutputTypes[type] == 0) return stdout;
537 else if (fOutputTypes[type] == 1) return stderr;
538 else if (fOutputTypes[type] == 2) {
539 if (!fOutputFiles[type]) {
541 ofstream* stream = NULL;
542 if (!fFileNames[type].IsNull()) {
543 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
544 if ((iType != type) &&
545 (fFileNames[iType].CompareTo(fFileNames[type]) == 0) &&
546 fOutputFiles[iType]) {
547 file = fOutputFiles[iType];
548 stream = fOutputStreams[iType];
553 file = fopen(fFileNames[type], "a");
554 stream = new ofstream(fFileNames[type], ios::app);
557 fOutputFiles[type] = file;
558 fOutputStreams[type] = stream;
559 if (!file) CloseFile(type);
561 if (fOutputFiles[type]) return fOutputFiles[type];
567 //_____________________________________________________________________________
570 // flush the output streams
572 if (!fgInstance) new AliLog;
573 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
574 if (fgInstance->fOutputFiles[iType]) {
575 fflush(fgInstance->fOutputFiles[iType]);
576 fgInstance->fOutputStreams[iType]->flush();
584 //_____________________________________________________________________________
585 void AliLog::SetHandleRootMessages(Bool_t on)
587 // enable or disable the handling of messages form root
589 if (!fgInstance) new AliLog;
591 SetErrorHandler(RootErrorHandler);
593 SetErrorHandler(DefaultErrorHandler);
598 //_____________________________________________________________________________
599 void AliLog::SetPrintType(Bool_t on)
601 // switch on or off the printing of the message type for all message types
603 if (!fgInstance) new AliLog;
604 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
605 fgInstance->fPrintType[iType] = on;
609 //_____________________________________________________________________________
610 void AliLog::SetPrintType(EType type, Bool_t on)
612 // switch on or off the printing of the message type for the given message type
614 if ((type < kFatal) || (type >= kMaxType)) return;
615 if (!fgInstance) new AliLog;
616 fgInstance->fPrintType[type] = on;
619 //_____________________________________________________________________________
620 void AliLog::SetPrintModule(Bool_t on)
622 // switch on or off the printing of the module for all message types
624 if (!fgInstance) new AliLog;
625 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
626 fgInstance->fPrintModule[iType] = on;
630 //_____________________________________________________________________________
631 void AliLog::SetPrintModule(EType type, Bool_t on)
633 // switch on or off the printing of the module for the given message type
635 if ((type < kFatal) || (type >= kMaxType)) return;
636 if (!fgInstance) new AliLog;
637 fgInstance->fPrintModule[type] = on;
640 //_____________________________________________________________________________
641 void AliLog::SetPrintScope(Bool_t on)
643 // switch on or off the printing of the scope/class name for all message types
645 if (!fgInstance) new AliLog;
646 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
647 fgInstance->fPrintScope[iType] = on;
651 //_____________________________________________________________________________
652 void AliLog::SetPrintScope(EType type, Bool_t on)
654 // switch on or off the printing of the scope/class name
655 // for the given message type
657 if ((type < kFatal) || (type >= kMaxType)) return;
658 if (!fgInstance) new AliLog;
659 fgInstance->fPrintScope[type] = on;
662 //_____________________________________________________________________________
663 void AliLog::SetPrintLocation(Bool_t on)
665 // switch on or off the printing of the file name and line number
666 // for all message types
668 if (!fgInstance) new AliLog;
669 for (Int_t iType = kFatal; iType < kMaxType; iType++) {
670 fgInstance->fPrintLocation[iType] = on;
674 //_____________________________________________________________________________
675 void AliLog::SetPrintLocation(EType type, Bool_t on)
677 // switch on or off the printing of the file name and line number
678 // for the given message type
680 if ((type < kFatal) || (type >= kMaxType)) return;
681 if (!fgInstance) new AliLog;
682 fgInstance->fPrintLocation[type] = on;
686 //_____________________________________________________________________________
687 void AliLog::SetPrintRepetitions(Bool_t on)
689 // switch on or off the printing of the number of repetitions of a message
690 // instead of repeating the same message
692 if (!fgInstance) new AliLog;
693 if (!on && (fgInstance->fRepetitions > 0)) fgInstance->PrintRepetitions();
694 fgInstance->fPrintRepetitions = on;
698 //_____________________________________________________________________________
699 void AliLog::WriteToFile(const char* name, Int_t option)
701 // write the log object with the given name and option to the current file
703 if (!fgInstance) new AliLog;
704 fgInstance->TObject::Write(name, option);
708 //_____________________________________________________________________________
709 UInt_t AliLog::GetLogLevel(const char* module, const char* className) const
711 // get the logging level for the given module and class
713 if (!fgInstance) new AliLog;
715 TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
716 if (obj) return obj->GetUniqueID();
719 TObject* obj = fgInstance->fModuleDebugLevels.FindObject(module);
720 if (obj) return obj->GetUniqueID();
722 return fgInstance->fGlobalLogLevel;
725 //_____________________________________________________________________________
726 Int_t AliLog::GetDebugLevel(const char* module, const char* className)
728 // get the debug level for the given module and class
730 if (!fgInstance) new AliLog;
731 return fgInstance->GetLogLevel(module, className) - kDebugOffset;
734 //_____________________________________________________________________________
735 void AliLog::PrintMessage(UInt_t type, const char* message,
736 const char* module, const char* className,
737 const char* function, const char* file, Int_t line)
739 // print the given message
741 // don't print the message if it is repeated
742 if (fPrintRepetitions &&
743 (fLastType == type) &&
744 (message && (fLastMessage.CompareTo(message) == 0)) &&
745 ((module && (fLastModule.CompareTo(module) == 0)) ||
746 (!module && fLastModule.IsNull())) &&
747 ((className && (fLastClassName.CompareTo(className) == 0)) ||
748 (!className && fLastClassName.IsNull())) &&
749 ((function && (fLastFunction.CompareTo(function) == 0)) ||
750 (!function && fLastFunction.IsNull()))&&
751 ((file && (fLastFile.CompareTo(file) == 0)) ||
752 (!file && fLastFile.IsNull())) &&
753 (fLastLine == line)) {
758 // print number of repetitions
759 if (fRepetitions > 0) PrintRepetitions();
761 // remember this message
764 fLastMessage = message;
765 fLastModule = module;
766 fLastClassName = className;
767 fLastFunction = function;
772 FILE* stream = GetOutputStream(type);
773 static const char* typeNames[kMaxType] =
774 {"Fatal", "Error", "Warning", "Info", "Debug"};
776 if (fPrintType[type]) {
777 fprintf(stream, "%c-", typeNames[type][0]);
779 if (fPrintModule[type] && module) {
780 fprintf(stream, "%s/", module);
782 if (fPrintScope[type] && className) {
783 fprintf(stream, "%s::", className);
786 fprintf(stream, "%s: %s", function, message);
788 fprintf(stream, "%s", function);
790 if (fPrintLocation[type] && file) {
791 fprintf(stream, " (%s:%.0d)", file, line);
794 fprintf(stream, "\n");
796 fprintf(stream, ": ");
800 //_____________________________________________________________________________
801 void AliLog::PrintRepetitions()
803 // print number of repetitions
805 fprintf(GetOutputStream(fLastType), " <message repeated %d time%s>\n",
806 fRepetitions, (fRepetitions > 1) ? "s" : "");
809 //_____________________________________________________________________________
810 void AliLog::Message(UInt_t level, const char* message,
811 const char* module, const char* className,
812 const char* function, const char* file, Int_t line)
814 // print a log message
816 if (!fgInstance) new AliLog;
818 // get the message type
820 if (type >= kMaxType) type = kMaxType - 1;
822 // print the message if the debug level allows
823 if (level <= fgInstance->GetLogLevel(module, className)) {
824 fgInstance->PrintMessage(type, message,
825 module, className, function, file, line);
828 // abort in case of a fatal message
829 if (type == kFatal) {
832 gSystem->StackTrace();
840 //_____________________________________________________________________________
841 void AliLog::Debug(UInt_t level, const char* message,
842 const char* module, const char* className,
843 const char* function, const char* file, Int_t line)
845 // print a debug message
847 if (level == 0) level = 1;
848 level += kDebugOffset;
849 Message(level, message, module, className, function, file, line);
853 //_____________________________________________________________________________
854 Int_t AliLog::RedirectStdoutTo(EType type, UInt_t level, const char* module,
855 const char* className, const char* function,
856 const char* file, Int_t line, Bool_t print)
858 // redirect the standard output to the stream of the given type
860 if (!fgInstance) new AliLog;
861 return fgInstance->RedirectTo(stdout, type, level, module, className,
862 function, file, line, print);
865 //_____________________________________________________________________________
866 Int_t AliLog::RedirectStderrTo(EType type, UInt_t level, const char* module,
867 const char* className, const char* function,
868 const char* file, Int_t line, Bool_t print)
870 // redirect the standard error output to the stream of the given type
872 if (!fgInstance) new AliLog;
873 return fgInstance->RedirectTo(stderr, type, level, module, className,
874 function, file, line, print);
877 //_____________________________________________________________________________
878 Int_t AliLog::RedirectTo(FILE* stream, EType type, UInt_t level,
879 const char* module, const char* className,
880 const char* function, const char* file, Int_t line,
883 // redirect the standard (error) output stream to the stream of the given type
885 // get the original file descriptor to be able to restore it later
886 Int_t original = dup(fileno(stream));
889 // flush the stream of the selected type
890 FILE* newStream = GetOutputStream(type);
894 if ((type == kDebug) && (level > 0)) level--;
895 if (type + level > GetLogLevel(module, className)) { // /dev/null
896 freopen("/dev/null", "a", stream);
897 } else if (fOutputTypes[type] == 0) { // stdout
898 if (stream != stdout) dup2(fileno(stdout), fileno(stream));
899 } else if (fOutputTypes[type] == 1) { // stderr
900 if (stream != stderr) dup2(fileno(stderr), fileno(stream));
901 } else if (fOutputTypes[type] == 2) { // file
902 freopen(fFileNames[type], "a", stream);
907 PrintMessage(type, NULL, module, className, function, file, line);
914 //_____________________________________________________________________________
915 void AliLog::RestoreStdout(Int_t original)
917 // restore the standard output
920 dup2(original, fileno(stdout));
924 //_____________________________________________________________________________
925 void AliLog::RestoreStderr(Int_t original)
927 // restore the standard error output
930 dup2(original, fileno(stderr));
935 //_____________________________________________________________________________
936 ostream& AliLog::Stream(EType type, UInt_t level,
937 const char* module, const char* className,
938 const char* function, const char* file, Int_t line)
940 // get the stream object for the given output type
942 if (!fgInstance) new AliLog;
943 return fgInstance->GetStream(type, level, module, className,
944 function, file, line);
947 //_____________________________________________________________________________
948 ostream& AliLog::GetStream(EType type, UInt_t level,
949 const char* module, const char* className,
950 const char* function, const char* file, Int_t line)
952 // get the stream object for the given output type
954 if ((type == kDebug) && (level > 0)) level--;
955 Bool_t noOutput = (type + level > GetLogLevel(module, className));
958 PrintMessage(type, NULL, module, className, function, file, line);
960 fflush(GetOutputStream(type));
962 static ofstream nullStream("/dev/null");
965 } else if (fOutputTypes[type] == 0) {
967 } else if (fOutputTypes[type] == 1) {
969 } else if (fOutputTypes[type] == 2) {
970 return *fOutputStreams[type];