ClassImp(AliLog)
-
+// implementation of a singleton here
AliLog* AliLog::fgInstance = NULL;
Bool_t AliLog::fgDebugEnabled = kTRUE;
+/**
+ * get root logger singleton instance
+ */
+AliLog *AliLog::GetRootLogger()
+{
+ if (fgInstance == NULL)
+ {
+ // creating singleton
+ fgInstance = new AliLog;
+ }
+
+ return fgInstance;
+}
-//_____________________________________________________________________________
+/**
+ * delete the root logger singleton instance
+ */
+void AliLog::DeleteRootLogger()
+{
+ if (fgInstance != NULL)
+ {
+ delete fgInstance;
+ fgInstance = NULL;
+ }
+}
+
+/**
+ * default private constructor
+ */
AliLog::AliLog() :
TObject(),
fGlobalLogLevel(kInfo),
{
// default constructor: set default values
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
fOutputTypes[iType] = 0;
fFileNames[iType] = "";
fOutputFiles[iType] = NULL;
fPrintLocation[iType] = (iType == kDebug);
}
+ // TO BE REVIEWED
// replace the previous instance by this one
if (fgInstance) delete fgInstance;
fgInstance = this;
ReadEnvSettings();
}
-//_____________________________________________________________________________
+/**
+ * private destructor
+ */
AliLog::~AliLog()
{
// destructor: clean up and reset instance pointer
if (fRepetitions > 0) PrintRepetitions();
- for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++) {
+ for (Int_t i = 0; i < fModuleDebugLevels.GetEntriesFast(); i++)
+ {
if (fModuleDebugLevels[i]) fModuleDebugLevels[i]->Delete();
}
+
fClassDebugLevels.Delete();
- for (Int_t i = 0; i < fClassDebugLevels.GetEntriesFast(); i++) {
+
+ for (Int_t i = 0; i < fClassDebugLevels.GetEntriesFast(); i++)
+ {
if (fClassDebugLevels[i]) fClassDebugLevels[i]->Delete();
}
+
fClassDebugLevels.Delete();
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
CloseFile(iType);
}
+
fflush(stderr);
fflush(stdout);
fgInstance = NULL;
}
+// NOT IMPLEMENTED!?
//_____________________________________________________________________________
AliLog::AliLog(const AliLog& log) :
TObject(log),
Fatal("AliLog", "copy constructor not implemented");
}
+// NOT IMPLEMENTED!?
//_____________________________________________________________________________
AliLog& AliLog::operator = (const AliLog& /*log*/)
{
}
+/**
+ * gSystem see TSystem.h
+ * gEnv see TEnv.h
+ *
+ * LOG_NO_DEBUG: fgDebugEnabled <- false
+ * AliRoot.AliLog.EnableDebug
+ * AliRoot.AliLog.GlobalLogLevel
+ */
//_____________________________________________________________________________
void AliLog::ReadEnvSettings()
{
// load settings from the root configuration file (.rootrc)
// and from environment variables
- static const char* typeNames[kMaxType] =
- {"kFatal", "kError", "kWarning", "kInfo", "kDebug"};
+ static const char* typeNames[kMaxType] = {"kFatal", "kError", "kWarning", "kInfo", "kDebug"};
// debug en- or disabling
- if (gSystem->Getenv("LOG_NO_DEBUG")) {
+ if (gSystem->Getenv("LOG_NO_DEBUG"))
+ {
fgDebugEnabled = kFALSE;
- } else if (gEnv->Defined("AliRoot.AliLog.EnableDebug")) {
- fgDebugEnabled = gEnv->GetValue("AliRoot.AliLog.EnableDebug",
- fgDebugEnabled);
+ }
+ else if (gEnv->Defined("AliRoot.AliLog.EnableDebug"))
+ {
+ fgDebugEnabled = gEnv->GetValue("AliRoot.AliLog.EnableDebug", fgDebugEnabled);
AliInfo(Form("debug %sabled", ((fgDebugEnabled) ? "en" : "dis")));
}
// global log level
- if (gEnv->Defined("AliRoot.AliLog.GlobalLogLevel")) {
+ if (gEnv->Defined("AliRoot.AliLog.GlobalLogLevel"))
+ {
const char* type = gEnv->GetValue("AliRoot.AliLog.GlobalLogLevel", "");
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
if (strcmp(type, typeNames[iType]) == 0) fGlobalLogLevel = iType;
}
+
AliDebug(3, Form("global log level set to %d", fGlobalLogLevel));
}
// global debug level
- if (gEnv->Defined("AliRoot.AliLog.GlobalDebugLevel")) {
- Int_t level = gEnv->GetValue("AliRoot.AliLog.GlobalDebugLevel",
- Int_t(fGlobalLogLevel - kDebugOffset));
+ if (gEnv->Defined("AliRoot.AliLog.GlobalDebugLevel"))
+ {
+ Int_t level = gEnv->GetValue("AliRoot.AliLog.GlobalDebugLevel", Int_t(fGlobalLogLevel - kDebugOffset));
if (level < -kDebugOffset) level = kDebugOffset;
fGlobalLogLevel = kDebugOffset + level;
- AliDebug(3, Form("global debug level set to %d",
- fGlobalLogLevel - kDebugOffset));
+ AliDebug(3, Form("global debug level set to %d", fGlobalLogLevel - kDebugOffset));
}
// module debug level
- if (gEnv->Defined("AliRoot.AliLog.ModuleDebugLevel")) {
+ if (gEnv->Defined("AliRoot.AliLog.ModuleDebugLevel"))
+ {
TString levels = gEnv->GetValue("AliRoot.AliLog.ModuleDebugLevel", "");
char* p = const_cast<char*>(levels.Data());
- while (const char* module = strtok(p, " ")) {
+
+ while (const char* module = strtok(p, " "))
+ {
p = NULL;
char* pos = const_cast<char*>(index(module, ':'));
if (!pos) continue;
}
// class debug level
- if (gEnv->Defined("AliRoot.AliLog.ClassDebugLevel")) {
+ if (gEnv->Defined("AliRoot.AliLog.ClassDebugLevel"))
+ {
TString levels = gEnv->GetValue("AliRoot.AliLog.ClassDebugLevel", "");
char* p = const_cast<char*>(levels.Data());
- while (const char* className = strtok(p, " ")) {
+
+ while (const char* className = strtok(p, " "))
+ {
p = NULL;
char* pos = const_cast<char*>(index(className, ':'));
if (!pos) continue;
*(pos++) = '\0';
Int_t level = atoi(pos);
SetClassDebugLevel(className, level);
- AliDebug(3, Form("debug level for class %s set to %d",
- className, level));
+ AliDebug(3, Form("debug level for class %s set to %d", className, level));
}
}
// general output stream
- if (gEnv->Defined("AliRoot.AliLog.Output")) {
+ if (gEnv->Defined("AliRoot.AliLog.Output"))
+ {
TString stream = gEnv->GetValue("AliRoot.AliLog.Output", "Standard");
- if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
+
+ if (stream.CompareTo("standard", TString::kIgnoreCase) == 0)
+ {
SetStandardOutput();
AliDebug(3, "output stream set to standard output for all types");
- } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
+ }
+ else if (stream.CompareTo("error", TString::kIgnoreCase) == 0)
+ {
SetErrorOutput();
AliDebug(3, "output stream set to error output for all types");
- } else if (!stream.IsNull()) {
+ }
+ else if (!stream.IsNull())
+ {
SetFileOutput(stream);
- AliDebug(3, Form("output stream set to file %s for all types",
- stream.Data()));
+ AliDebug(3, Form("output stream set to file %s for all types", stream.Data()));
}
}
// individual output streams
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
TString name("AliRoot.AliLog.Output.");
name += &typeNames[iType][1];
- if (gEnv->Defined(name)) {
+
+ if (gEnv->Defined(name))
+ {
TString stream = gEnv->GetValue(name, "Standard");
- if (stream.CompareTo("standard", TString::kIgnoreCase) == 0) {
+
+ if (stream.CompareTo("standard", TString::kIgnoreCase) == 0)
+ {
SetStandardOutput(EType_t(iType));
- AliDebug(3, Form("output stream set to standard output for type %s",
- typeNames[iType]));
- } else if (stream.CompareTo("error", TString::kIgnoreCase) == 0) {
+ AliDebug(3, Form("output stream set to standard output for type %s", typeNames[iType]));
+ }
+ else if (stream.CompareTo("error", TString::kIgnoreCase) == 0)
+ {
SetErrorOutput(EType_t(iType));
- AliDebug(3, Form("output stream set to error output for type %s",
- typeNames[iType]));
- } else if (!stream.IsNull()) {
+ AliDebug(3, Form("output stream set to error output for type %s", typeNames[iType]));
+ }
+ else if (!stream.IsNull())
+ {
SetFileOutput(EType_t(iType), stream);
- AliDebug(3, Form("output stream set to file %s for type %s",
- stream.Data(), typeNames[iType]));
+ AliDebug(3, Form("output stream set to file %s for type %s", stream.Data(), typeNames[iType]));
}
}
}
// handling of root error messages
- if (gEnv->Defined("AliRoot.AliLog.HandleRootMessages")) {
+ if (gEnv->Defined("AliRoot.AliLog.HandleRootMessages"))
+ {
Bool_t on = gEnv->GetValue("AliRoot.AliLog.HandleRootMessages", kTRUE);
SetHandleRootMessages(on);
- AliDebug(3, Form("handling of root messages %sabled",
- ((on) ? "en" : "dis")));
+ AliDebug(3, Form("handling of root messages %sabled", ((on) ? "en" : "dis")));
}
// printout settings
- static const char* settingNames[4] =
- {"Type", "Module", "Scope", "Location"};
- Bool_t* settings[] =
- {fPrintType, fPrintModule, fPrintScope, fPrintLocation};
- for (Int_t iSetting = 0; iSetting < 4; iSetting++) {
+ static const char* settingNames[4] = {"Type", "Module", "Scope", "Location"};
+ Bool_t* settings[] = {fPrintType, fPrintModule, fPrintScope, fPrintLocation};
+
+ for (Int_t iSetting = 0; iSetting < 4; iSetting++)
+ {
TString name("AliRoot.AliLog.Print");
name += settingNames[iSetting];
- if (gEnv->Defined(name)) {
+
+ if (gEnv->Defined(name))
+ {
Bool_t on = gEnv->GetValue(name, settings[iSetting][0]);
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
settings[iSetting][iType] = on;
}
- AliDebug(3, Form("printing of %s %sabled for all types",
- settingNames[iSetting], ((on) ? "en" : "dis")));
+ AliDebug(3, Form("printing of %s %sabled for all types", settingNames[iSetting], ((on) ? "en" : "dis")));
}
- for (Int_t iType = kFatal; iType < kMaxType; iType++) {
+ for (Int_t iType = kFatal; iType < kMaxType; iType++)
+ {
TString nameType = name + "." + &typeNames[iType][1];
- if (gEnv->Defined(nameType)) {
+
+ if (gEnv->Defined(nameType))
+ {
Bool_t on = gEnv->GetValue(nameType, settings[iSetting][iType]);
settings[iSetting][iType] = on;
- AliDebug(3, Form("printing of %s %sabled for type %s",
- settingNames[iSetting], ((on) ? "en" : "dis"),
- typeNames[iType]));
+ AliDebug(3, Form("printing of %s %sabled for type %s", settingNames[iSetting], ((on) ? "en" : "dis"), typeNames[iType]));
}
}
}
// repetition of messages
- if (gEnv->Defined("AliRoot.AliLog.PrintRepetitions")) {
+ 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")));
+ AliDebug(3, Form("printing of message repetitions %sabled", ((on) ? "en" : "dis")));
}
}
{
// new error handler for messages from root
- switch (level) {
+ switch (level)
+ {
case ::kFatal : level = kFatal; break;
case ::kSysError :
DefaultErrorHandler(level, abort, location, message);
}
+// DEPRECATED: USE A CONFIGURATION FILE INSTEAD
//_____________________________________________________________________________
void AliLog::EnableDebug(Bool_t enabled)
{
{
// set the global debug level
+ // TO BE DELETED
if (!fgInstance) new AliLog;
fgInstance->fGlobalLogLevel = type;
}
/* $Id$ */
-///
-/// class for logging debug, info and error messages
-///
-
#include <TObject.h>
#include <TObjArray.h>
#include <TString.h>
+// deprecation macro
+#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
+#define ALIROOT_DEPRECATED(func) func __attribute__ ((deprecated))
+#elif defined(_MSC_VER) && _MSC_VER >= 1300
+#define ALIROOT_DEPRECATED(func) __declspec(deprecated) func
+# else
+#define ALIROOT_DEPRECATED(func) func
+#endif
-class AliLog: public TObject {
+/**
+ * class for logging debug, info and error messages
+ */
+class AliLog: public TObject
+{
public:
- AliLog();
- virtual ~AliLog();
- static AliLog* Instance() {return fgInstance;}
+ // Log4j log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL
enum EType_t {kFatal = 0, kError, kWarning, kInfo, kDebug, kMaxType};
typedef void (*AliLogNotification)(EType_t type, const char* message );
+ // NB: singleton constructor & destructor should not be public!
+ // ALIROOT_DEPRECATED(AliLog());
+ // ALIROOT_DEPRECATED(virtual ~AliLog());
+
+ // NB: singleton deprecated static instance method
+ // ALIROOT_DEPRECATED(static AliLog* Instance() {return fgInstance;};)
+
+ // get root logger singleton instance
+ static AliLog *GetRootLogger();
+ // delete root logger singleton instance
+ static void DeleteRootLogger();
+
+ // NB: the following functions should not be static
+ // NB: deprecated: logging configuration should be made through to a configuration file
static void EnableDebug(Bool_t enabled);
static void SetGlobalLogLevel(EType_t type);
static Int_t GetGlobalLogLevel();
const char* function, const char* file, Int_t line);
private:
+
+ // constructor is made private for implementing a singleton
+ AliLog();
+ virtual ~AliLog();
+
+ // NOT IMPLEMENTED?
AliLog(const AliLog& log);
AliLog& operator = (const AliLog& log);
enum {kDebugOffset = kDebug-1};
static AliLog* fgInstance; //! pointer to current instance
-
static Bool_t fgDebugEnabled; // flag for debug en-/disabling
UInt_t fGlobalLogLevel; // global logging level
};
-// module name
+// module name macro
#ifdef _MODULE_
#define MODULENAME() _MODULE_
#else
#define MODULENAME() "NoModule"
#endif
-// function name
+// function name macro
#if defined(__GNUC__) || defined(__ICC) || defined(__ECC) || defined(__APPLE__)
#define FUNCTIONNAME() __FUNCTION__
// #elif defined(__HP_aCC) || defined(__alpha) || defined(__DECCXX)
// inspired by log4cxx code (see log4cxx/Logger.h)
// implements GCC branch prediction for increasing logging performance
#if !defined(ALIROOT_UNLIKELY)
-#if __GNUC__ >= 3
+#if defined(__GNUC__) && (__GNUC__ >= 3)
/**
Provides optimization hint to the compiler
to optimize for the expression being false.
#define AliInfoClassStream() AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), Class()->GetName(), FUNCTIONNAME(), __FILE__, __LINE__)
#define AliInfoGeneralStream(scope) AliLog::Stream(AliLog::kInfo, 0, MODULENAME(), scope, FUNCTIONNAME(), __FILE__, __LINE__)
-
// warning messages
#ifdef LOG_NO_WARNING
#define AliWarning(message)