#include "AliLog.h"
+using std::endl;
+using std::cout;
+using std::ostream;
+using std::cerr;
+using std::ofstream;
+using std::ios;
ClassImp(AliLog)
// implementation of a singleton here
AliLog* AliLog::fgInstance = NULL;
Bool_t AliLog::fgDebugEnabled = kTRUE;
+Bool_t AliLog::fgCoreEnabled = kFALSE;
/**
* get root logger singleton instance
fPrintRepetitions = on;
AliDebug(3, Form("printing of message repetitions %sabled", ((on) ? "en" : "dis")));
}
+ if (gSystem->Getenv("ALIROOT_FORCE_COREDUMP")){
+ EnableCoreDump(kTRUE);
+ }
+
}
fgDebugEnabled = enabled;
}
+void AliLog::EnableCoreDump(Bool_t enabled)
+{
+// enable or disable debug output
+
+ fgCoreEnabled = enabled;
+ gSystem->ResetSignal(kSigFloatingException,enabled);
+ gSystem->ResetSignal(kSigSegmentationViolation,enabled);
+ if (enabled) printf("Core dump enabled\n");
+ else {
+ printf("Core dump disabled\n");
+ }
+}
+
+
+
//_____________________________________________________________________________
void AliLog::SetGlobalLogLevel(EType_t type)
{
delete fgInstance;
if (gSystem) {
gSystem->StackTrace();
+ if (fgCoreEnabled) MakeCoreDump("core.AliRoot");
gSystem->Abort();
} else {
+ if (fgCoreEnabled) MakeCoreDump("core.AliRoot");
::abort();
}
}
}
+
+
//_____________________________________________________________________________
void AliLog::Debug(UInt_t level, const char* message,
const char* module, const char* className,
// redirect stream
if ((type == kDebug) && (level > 0)) level--;
if (type + level > GetLogLevel(module, className)) { // /dev/null
- freopen("/dev/null", "a", stream);
+ if(!freopen("/dev/null", "a", stream)) AliWarning("Cannot reopen /dev/null");
} else if (fOutputTypes[type] == 0) { // stdout
if (stream != stdout) dup2(fileno(stdout), fileno(stream));
} else if (fOutputTypes[type] == 1) { // stderr
if (stream != stderr) dup2(fileno(stderr), fileno(stream));
} else if (fOutputTypes[type] == 2) { // file
- freopen(fFileNames[type], "a", stream);
+ if(!freopen(fFileNames[type], "a", stream)) AliWarning(Form("Cannot reopen %s",fFileNames[type].Data()));
} else if (fOutputTypes[type] == 3) { // external C++ stream
// redirection is not possible for external C++ streams
}
}
va_end(ap);
}
+
+
+void AliLog::MakeCoreDump(const char *fout){
+ //
+ // Functionality to make a program snapshot
+ // gcore - Generate a core file for a running process
+ // gcore dmake a current snapshot, program can continue further
+ // We assum that gcore is installed
+ // for details see: man gcore
+ //
+ // Example use - make default core file for current process: AliLog::MakeCoreDump(0)
+ //
+ //
+ // Automatic core dump creation in case of the AliFatal can be specified using
+ // static void EnableCoreDump(Bool_t enabled);
+ // Core dump is created in addition to the stack trace ()
+ // marian.ivanov@cern.ch
+ //
+ if (!gSystem) return;
+ printf("AliLog::MakeCoreDump\n");
+ if (fout){
+ gSystem->Exec(Form("gcore -o %s %d",fout, gSystem->GetPid()));
+ }else{
+ gSystem->Exec(Form("gcore %d", gSystem->GetPid()));
+ }
+}