// @(#) $Id$
/**************************************************************************
- * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ * This file is property of and copyright by the ALICE HLT Project *
+ * ALICE Experiment at CERN, All rights reserved. *
* *
- * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
- * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
- * for The ALICE Off-line Project. *
+ * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
+ * for The ALICE HLT Project. *
* *
* Permission to use, copy, modify and distribute this software and its *
* documentation strictly for non-commercial purposes is hereby granted *
using namespace std;
#endif
-#ifndef NOALIROOT_LOGGING
-#include "AliLog.h"
-#endif
#include "AliHLTStdIncludes.h"
#include "AliHLTLogging.h"
+#include "AliHLTComponentHandler.h"
#include "TString.h"
#include "Varargs.h"
#include <string>
#include <sstream>
#include <iostream>
-#ifndef NOALIROOT_LOGGING
-/**
- * Notification callback for AliRoot logging methods
- */
-void LogNotification(AliLog::EType_t level, const char* message)
-{
- AliHLTLogging hltlog;
- hltlog.SwitchAliLog(0);
- hltlog.Logging(kHLTLogInfo, "NotificationHandler", "AliLog", AliHLTLogging::fgLogstr.str().c_str());
- AliHLTLogging::fgLogstr.clear();
- string empty("");
- AliHLTLogging::fgLogstr.str(empty);
-}
-#endif
-
/** ROOT macro for the implementation of ROOT specific class methods */
-ClassImp(AliHLTLogging)
+ClassImp(AliHLTLogging);
AliHLTLogging::AliHLTLogging()
:
- //fLocalLogFilter(kHLTLogDefault),
- fLocalLogFilter(kHLTLogAll),
+ fLocalLogFilter(fgLocalLogDefault),
fpDefaultKeyword(NULL),
fpCurrentKeyword(NULL)
{
ostringstream AliHLTLogging::fgLogstr;
AliHLTComponentLogSeverity AliHLTLogging::fgGlobalLogFilter=kHLTLogAll;
+AliHLTComponentLogSeverity AliHLTLogging::fgLocalLogDefault=kHLTLogAll;
AliHLTfctLogging AliHLTLogging::fgLoggingFunc=NULL;
+AliHLTLogging::AliHLTDynamicMessage AliHLTLogging::fgAliLoggingFunc=NULL;
int AliHLTLogging::fgUseAliLog=1;
+TString AliHLTLogging::fgBlackList="";
+TString AliHLTLogging::fgWhiteList="";
+
AliHLTLogging::~AliHLTLogging()
{
// see header file for class documentation
}
+// the array will be grown dynamically, this is just an initial size
TArrayC AliHLTLogging::fgAliHLTLoggingTarget(200);
+// the maximum size of the array
const int AliHLTLogging::fgkALIHLTLOGGINGMAXBUFFERSIZE=10000;
int AliHLTLogging::Init(AliHLTfctLogging pFun)
(*fgLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function");
}
fgLoggingFunc=pFun;
- // older versions of AliLog does not support the notification callback and
- // stringstreams, but they support the logging macros in general
-#ifndef NOALIROOT_LOGGING
-#ifndef NO_ALILOG_NOTIFICATION
- AliLog* log=new AliLog;
- log->SetLogNotification(LogNotification);
- log->SetStreamOutput(&fgLogstr);
-#endif // NO_ALILOG_NOTIFICATION
-#endif // NOALIROOT_LOGGING
return 0;
}
+int AliHLTLogging::InitAliLogTrap(AliHLTComponentHandler* pHandler)
+{
+ // see header file for class documentation
+ // init the AliRoot logging trap
+ // AliLog messages are redirected to PubSub,
+ int iResult=0;
+ if (pHandler) {
+ // set temporary loglevel of component handler
+ AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel();
+ pHandler->SetLocalLoggingLevel(kHLTLogError);
+
+ // load library containing AliRoot dependencies and initialization handler
+ pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */);
+
+ // restore loglevel
+ pHandler->SetLocalLoggingLevel(loglevel);
+
+ // find the symbol
+ InitAliDynamicMessageCallback pFunc=(InitAliDynamicMessageCallback)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "InitAliDynamicMessageCallback");
+ if (pFunc) {
+ iResult=(*pFunc)();
+ } else {
+ Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogTrap", "init logging",
+ "can not initialize AliLog callback");
+ iResult=-ENOSYS;
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+
+ return iResult;
+}
+
+int AliHLTLogging::InitAliLogFunc(AliHLTComponentHandler* pHandler)
+{
+ // see header file for class documentation
+ int iResult=0;
+ if (pHandler) {
+ // set temporary loglevel of component handler
+ AliHLTComponentLogSeverity loglevel=pHandler->GetLocalLoggingLevel();
+ pHandler->SetLocalLoggingLevel(kHLTLogError);
+
+ // load library containing AliRoot dependencies and initialization handler
+ pHandler->LoadLibrary(ALILOG_WRAPPER_LIBRARY, 0/* do not activate agents */);
+
+ // restore loglevel
+ pHandler->SetLocalLoggingLevel(loglevel);
+
+ // find the symbol
+ fgAliLoggingFunc=(AliHLTLogging::AliHLTDynamicMessage)pHandler->FindSymbol(ALILOG_WRAPPER_LIBRARY, "AliDynamicMessage");
+ if (fgAliLoggingFunc==NULL) {
+ Message(NULL, kHLTLogError, "AliHLTLogging::InitAliLogFunc", "init logging",
+ "symbol lookup failure: can not find AliDynamicMessage, switching to HLT logging system");
+ iResult=-ENOSYS;
+ }
+ } else {
+ iResult=-EINVAL;
+ }
+
+ return iResult;
+}
+
int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity,
const char* origin, const char* keyword,
const char* message)
case kHLTLogFatal:
strSeverity="fatal";
break;
+ case kHLTLogImportant:
+ strSeverity="notify";
+ break;
default:
break;
}
return iResult;
}
-#ifndef NOALIROOT_LOGGING
+#if 0
int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity,
const char* originClass, const char* originFunc,
const char* file, int line, const char* message)
}
#endif
-const char* AliHLTLogging::BuildLogString(const char *format, va_list ap)
+const char* AliHLTLogging::BuildLogString(const char *format, va_list ap, bool bAppend)
{
// see header file for class documentation
const char* fmt = format;
if (fmt==NULL) fmt=va_arg(ap, const char*);
- fgAliHLTLoggingTarget[0]=0;
+ unsigned int iOffset=0;
+ if (bAppend) {
+ iOffset=strlen(fgAliHLTLoggingTarget.GetArray());
+ } else {
+ fgAliHLTLoggingTarget[0]=0;
+ }
while (fmt!=NULL) {
- iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap);
+ iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray()+iOffset, fgAliHLTLoggingTarget.GetSize()-iOffset, fmt, ap);
if (iResult==-1)
// for compatibility with older version of vsnprintf
iResult=fgAliHLTLoggingTarget.GetSize()*2;
- else if (iResult<fgAliHLTLoggingTarget.GetSize())
+ else
+ iResult+=iOffset;
+
+ if (iResult<fgAliHLTLoggingTarget.GetSize())
+ // everything in the limit
break;
// terminate if buffer is already at the limit
return fgAliHLTLoggingTarget.GetArray();
}
+const char* AliHLTLogging::SetLogString(const void* p, const char* pfmt, const char *format, ...)
+{
+ // see header file for class documentation
+ if (!p || !pfmt) return NULL;
+ TString formatstr=format;
+ TString pstr;
+#ifdef __DEBUG
+ pstr.Form(pfmt, p);
+#endif
+ formatstr.ReplaceAll("_pfmt_", pstr);
+ va_list args;
+ va_start(args, format);
+
+ const char* message=BuildLogString(formatstr.Data(), args);
+ va_end(args);
+
+ return message;
+}
+
int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity,
const char* origin, const char* keyword,
const char* format, ... )
if (fgLoggingFunc) {
iResult = (*fgLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
} else {
-#ifndef NOALIROOT_LOGGING
- if (fgUseAliLog)
- iResult=AliMessage(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
+ if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
+ iResult=(*fgAliLoggingFunc)(severity, NULL, origin, NULL, 0, AliHLTLogging::BuildLogString(format, args ));
else
-#endif
iResult=Message(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args ));
}
va_end(args);
const char* file, int line, ... ) const
{
// see header file for class documentation
+ int iResult=0;
- if (file==NULL && line==0) {
- // this is currently just to get rid of the warning "unused parameter"
+ va_list args;
+ va_start(args, line);
+
+ iResult=SendMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args ));
+ va_end(args);
+
+ return iResult;
+}
+
+int AliHLTLogging::SendMessage(AliHLTComponentLogSeverity severity,
+ const char* originClass, const char* originFunc,
+ const char* file, int line,
+ const char* message) const
+{
+ // see header file for class documentation
+ int iResult=0;
+ const char* separator="";
+ TString origin;
+ if (originClass) {
+ origin+=originClass;
+ separator="::";
+ }
+ if (originFunc) {
+ origin+=separator;
+ origin+=originFunc;
}
- int iResult=CheckFilter(severity);
- if (iResult>0) {
- const char* separator="";
- TString origin;
- if (originClass) {
- origin+=originClass;
- separator="::";
- }
- if (originFunc) {
- origin+=separator;
- origin+=originFunc;
- }
- va_list args;
- va_start(args, line);
- if (fgLoggingFunc) {
- iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
- } else {
-#ifndef NOALIROOT_LOGGING
- if (fgUseAliLog)
- iResult=AliMessage(severity, originClass, originFunc, file, line, AliHLTLogging::BuildLogString(NULL, args ));
- else
-#endif
- iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args ));
- }
- va_end(args);
+ if (fgLoggingFunc) {
+ iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), message);
+ } else {
+ if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL)
+ iResult=(*fgAliLoggingFunc)(severity, originClass, originFunc, file, line, message);
+ else
+ iResult=Message(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), message);
}
return iResult;
}
{
// see header file for class documentation
- int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0;
+ int iResult=severity==kHLTLogNone || ((severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0);
return iResult;
}
fgGlobalLogFilter=level;
}
+AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel()
+{
+ // see header file for class documentation
+
+ return fgGlobalLogFilter;
+}
+
void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level)
{
// see header file for class documentation
fLocalLogFilter=level;
}
+
+
+AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel()
+{
+ // see header file for class documentation
+
+ return fLocalLogFilter;
+}
+
+void AliHLTLogging::SetLocalLoggingDefault(AliHLTComponentLogSeverity level)
+{
+ // see header file for class documentation
+ fgLocalLogDefault=level;
+}
+
+int AliHLTLogging::CheckGroup(const char* /*originClass*/) const
+{
+ // see header file for class documentation
+
+ return 1;
+}
+
+int AliHLTLogging::SetBlackList(const char* classnames)
+{
+ // see header file for class documentation
+
+ if (classnames)
+ fgBlackList=classnames;
+ return 0;
+}
+
+int AliHLTLogging::SetWhiteList(const char* classnames)
+{
+ // see header file for class documentation
+
+ if (classnames)
+ fgWhiteList=classnames;
+ return 0;
+}