TObject(),
fGlobalLogLevel(kInfo),
fModuleDebugLevels(),
- fClassDebugLevels()
+ fClassDebugLevels(),
+ fPrintRepetitions(kTRUE),
+ fRepetitions(0),
+ fLastType(0),
+ fLastMessage(),
+ fLastModule(),
+ fLastClassName(),
+ fLastFunction(),
+ fLastFile(),
+ fLastLine(0)
{
// default constructor: set default values
fPrintLocation[iType] = (iType == kDebug);
}
- SetHandleRootMessages(kTRUE);
-
// replace the previous instance by this one
if (fgInstance) delete fgInstance;
fgInstance = this;
+ SetHandleRootMessages(kTRUE);
+
// read the .rootrc settings
ReadEnvSettings();
}
{
// destructor: clean up and reset instance pointer
+ if (fRepetitions > 0) PrintRepetitions();
+
for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++) {
if (fModuleDebugLevels[i]) fModuleDebugLevels[i]->Delete();
}
}
}
}
+
+ // repetition of messages
+ if (gEnv->Defined("AliRoot.AliLog.PrintRepetitions")) {
+ Bool_t on = gEnv->GetValue("AliRoot.AliLog.PrintRepetitions", kTRUE);
+ fPrintRepetitions = on;
+ AliDebug(3, Form("printing of message repetitions %sabled",
+ ((on) ? "en" : "dis")));
+ }
}
{
// enable or disable the handling of messages form root
+ if (!fgInstance) new AliLog;
if (on) {
SetErrorHandler(RootErrorHandler);
} else {
}
+//_____________________________________________________________________________
+void AliLog::SetPrintRepetitions(Bool_t on)
+{
+// switch on or off the printing of the number of repetitions of a message
+// instead of repeating the same message
+
+ if (!fgInstance) new AliLog;
+ if (!on && (fgInstance->fRepetitions > 0)) fgInstance->PrintRepetitions();
+ fgInstance->fPrintRepetitions = on;
+}
+
+
//_____________________________________________________________________________
void AliLog::Write(const char* name, Int_t option)
{
{
// print the given message
+ // don't print the message if it is repeated
+ if (fPrintRepetitions &&
+ (fLastType == type) &&
+ (message && (fLastMessage.CompareTo(message) == 0)) &&
+ ((module && (fLastModule.CompareTo(module) == 0)) ||
+ (!module && fLastModule.IsNull())) &&
+ ((className && (fLastClassName.CompareTo(className) == 0)) ||
+ (!className && fLastClassName.IsNull())) &&
+ ((function && (fLastFunction.CompareTo(function) == 0)) ||
+ (!function && fLastFunction.IsNull()))&&
+ ((file && (fLastFile.CompareTo(file) == 0)) ||
+ (!file && fLastFile.IsNull())) &&
+ (fLastLine == line)) {
+ fRepetitions++;
+ return;
+ }
+
+ // print number of repetitions
+ if (fRepetitions > 0) PrintRepetitions();
+
+ // remember this message
+ fRepetitions = 0;
+ fLastType = type;
+ fLastMessage = message;
+ fLastModule = module;
+ fLastClassName = className;
+ fLastFunction = function;
+ fLastFile = file;
+ fLastLine = line;
+
+ // print the message
FILE* stream = GetOutputStream(type);
static const char* typeNames[kMaxType] =
{"Fatal", "Error", "Warning", "Info", "Debug"};
}
}
+//_____________________________________________________________________________
+void AliLog::PrintRepetitions()
+{
+// print number of repetitions
+
+ fprintf(GetOutputStream(fLastType), " <message repeated %d time%s>\n",
+ fRepetitions, (fRepetitions > 1) ? "s" : "");
+}
+
//_____________________________________________________________________________
void AliLog::Message(UInt_t level, const char* message,
const char* module, const char* className,
static void SetPrintLocation(Bool_t on);
static void SetPrintLocation(EType type, Bool_t on);
+ static void SetPrintRepetitions(Bool_t on);
+
static void Write(const char* name, Int_t option = 0);
// the following public methods are used by the preprocessor macros
const char* module, const char* className,
const char* function,
const char* file, Int_t line);
+ void PrintRepetitions();
Int_t RedirectTo(FILE* stream, EType type, UInt_t level,
const char* module, const char* className,
Bool_t fPrintScope[kMaxType]; // print scope/class name on/off
Bool_t fPrintLocation[kMaxType]; // print file and line on/off
+ Bool_t fPrintRepetitions; // print number of repetitions instead of repeated message on/off
+
+ Int_t fRepetitions; //! counter of repetitions
+ UInt_t fLastType; //! type of last message
+ TString fLastMessage; //! last message
+ TString fLastModule; //! module name of last message
+ TString fLastClassName; //! class name of last message
+ TString fLastFunction; //! function name of last message
+ TString fLastFile; //! file name of last message
+ Int_t fLastLine; //! line number of last message
+
ClassDef(AliLog, 1) // class for logging debug, info and error messages
};