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::Write(const char* name, Int_t option)
+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::WriteToFile(const char* name, Int_t option)
{
// write the log object with the given name and option to the current file
// get the logging level for the given module and class
if (!fgInstance) new AliLog;
- TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
- if (obj) return obj->GetUniqueID();
- obj = fgInstance->fModuleDebugLevels.FindObject(module);
- if (obj) return obj->GetUniqueID();
+ if (className) {
+ TObject* obj = fgInstance->fClassDebugLevels.FindObject(className);
+ if (obj) return obj->GetUniqueID();
+ }
+ if (module) {
+ TObject* obj = fgInstance->fModuleDebugLevels.FindObject(module);
+ if (obj) return obj->GetUniqueID();
+ }
return fgInstance->fGlobalLogLevel;
}
{
// 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"};
if (fPrintType[type]) {
- fprintf(stream, "%s in ", typeNames[type]);
+ fprintf(stream, "%c-", typeNames[type][0]);
}
- fprintf(stream, "<");
if (fPrintModule[type] && module) {
fprintf(stream, "%s/", module);
}
fprintf(stream, "%s::", className);
}
if (message) {
- fprintf(stream, "%s>: %s", function, message);
+ fprintf(stream, "%s: %s", function, message);
} else {
- fprintf(stream, "%s>", function);
+ fprintf(stream, "%s", function);
}
if (fPrintLocation[type] && file) {
fprintf(stream, " (%s:%.0d)", file, line);
}
}
+//_____________________________________________________________________________
+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,
fflush(stdout);
dup2(original, fileno(stdout));
+ close(original);
}
//_____________________________________________________________________________
fflush(stderr);
dup2(original, fileno(stderr));
+ close(original);
}