X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=HLT%2FBASE%2FAliHLTLogging.cxx;h=564f1ad7f48d29a33b3f2c1028b17d623c2b3755;hb=b9f858e15e8d5ab3f5f0dd3f06adc99d8e3dec1d;hp=017e009b223f299bce88e28fd5ef27abc76817c7;hpb=a59b461eaee15bcdd1fd663a4908fe8ec7d7cb36;p=u%2Fmrichter%2FAliRoot.git diff --git a/HLT/BASE/AliHLTLogging.cxx b/HLT/BASE/AliHLTLogging.cxx index 017e009b223..564f1ad7f48 100644 --- a/HLT/BASE/AliHLTLogging.cxx +++ b/HLT/BASE/AliHLTLogging.cxx @@ -1,11 +1,11 @@ // @(#) $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 * - * Timm Steinbeck * - * for The ALICE Off-line Project. * + * Primary Authors: Matthias Richter * + * 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 * @@ -26,48 +26,17 @@ using namespace std; #endif -#ifndef NOALIROOT_LOGGING -#include "AliLog.h" -#endif #include "AliHLTStdIncludes.h" #include "AliHLTLogging.h" +#include "AliHLTComponentHandler.h" #include "TString.h" -#include "TArrayC.h" #include "Varargs.h" #include #include #include -/** target stream for AliRoot logging methods */ -ostringstream gLogstr; - -#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", gLogstr.str().c_str()); - gLogstr.clear(); - string empty(""); - gLogstr.str(empty); -} -#endif - -/** - * The global logging buffer. - * The buffer is created with an initial size and grown dynamically on - * demand. - */ -TArrayC gAliHLTLoggingTarget(200); - -/** the maximum size of the buffer */ -const int gALIHLTLOGGING_MAXBUFFERSIZE=10000; - /** ROOT macro for the implementation of ROOT specific class methods */ -ClassImp(AliHLTLogging) +ClassImp(AliHLTLogging); AliHLTLogging::AliHLTLogging() : @@ -100,35 +69,98 @@ AliHLTLogging& AliHLTLogging::operator=(const AliHLTLogging&) return *this; } -AliHLTComponentLogSeverity AliHLTLogging::fGlobalLogFilter=kHLTLogAll; -AliHLTfctLogging AliHLTLogging::fLoggingFunc=NULL; +ostringstream AliHLTLogging::fgLogstr; +AliHLTComponentLogSeverity AliHLTLogging::fgGlobalLogFilter=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) { // see header file for class documentation - if (fLoggingFunc!=NULL && fLoggingFunc!=pFun) { - (*fLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function"); + if (fgLoggingFunc!=NULL && fgLoggingFunc!=pFun) { + (*fgLoggingFunc)(NULL/*fParam*/, kHLTLogWarning, "AliHLTLogging::Init", "no key", "overriding previously initialized logging function"); } - fLoggingFunc=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(&gLogstr); -#endif // NO_ALILOG_NOTIFICATION -#endif // NOALIROOT_LOGGING + fgLoggingFunc=pFun; 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 lookp 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) @@ -159,12 +191,15 @@ int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, case kHLTLogFatal: strSeverity="fatal"; break; + case kHLTLogImportant: + strSeverity="notify"; + break; default: break; } TString out="HLT Log "; out+=strSeverity; - if (origin) {out+=": "; out+=origin;} + if (origin && origin[0]!=0) {out+=": <"; out+=origin; out+="> ";} out+=" "; out+=message; if (keyword!=NULL && strcmp(keyword, HLT_DEFAULT_LOG_KEYWORD)!=0) { out+=" ("; out+=keyword; out +=")"; @@ -173,31 +208,31 @@ int AliHLTLogging::Message(void *param, AliHLTComponentLogSeverity severity, return iResult; } -#ifndef NOALIROOT_LOGGING +#if 0 int AliHLTLogging::AliMessage(AliHLTComponentLogSeverity severity, - const char* origin_class, const char* origin_func, + const char* originClass, const char* originFunc, const char* file, int line, const char* message) { // see header file for class documentation switch (severity) { case kHLTLogBenchmark: - AliLog::Message(AliLog::kInfo, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); break; case kHLTLogDebug: - AliLog::Message(AliLog::kDebug, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kDebug, message, "HLT", originClass, originFunc, file, line); break; case kHLTLogInfo: - AliLog::Message(AliLog::kInfo, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kInfo, message, "HLT", originClass, originFunc, file, line); break; case kHLTLogWarning: - AliLog::Message(AliLog::kWarning, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); break; case kHLTLogError: - AliLog::Message(AliLog::kError, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kError, message, "HLT", originClass, originFunc, file, line); break; case kHLTLogFatal: - AliLog::Message(AliLog::kWarning, message, "HLT", origin_class, origin_func, file, line); + AliLog::Message(AliLog::kWarning, message, "HLT", originClass, originFunc, file, line); break; default: break; @@ -221,32 +256,32 @@ const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) const char* fmt = format; if (fmt==NULL) fmt=va_arg(ap, const char*); - gAliHLTLoggingTarget[0]=0; + fgAliHLTLoggingTarget[0]=0; while (fmt!=NULL) { - iResult=vsnprintf(gAliHLTLoggingTarget.GetArray(), gAliHLTLoggingTarget.GetSize(), fmt, ap); + iResult=vsnprintf(fgAliHLTLoggingTarget.GetArray(), fgAliHLTLoggingTarget.GetSize(), fmt, ap); if (iResult==-1) // for compatibility with older version of vsnprintf - iResult=gAliHLTLoggingTarget.GetSize()*2; - else if (iResult=gALIHLTLOGGING_MAXBUFFERSIZE) + if (fgAliHLTLoggingTarget.GetSize()>=fgkALIHLTLOGGINGMAXBUFFERSIZE) { - gAliHLTLoggingTarget[gAliHLTLoggingTarget.GetSize()-1]=0; + fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; break; } // check limitation and grow the buffer - if (iResult>gALIHLTLOGGING_MAXBUFFERSIZE) iResult=gALIHLTLOGGING_MAXBUFFERSIZE; - gAliHLTLoggingTarget.Set(iResult+1); + if (iResult>fgkALIHLTLOGGINGMAXBUFFERSIZE) iResult=fgkALIHLTLOGGINGMAXBUFFERSIZE; + fgAliHLTLoggingTarget.Set(iResult+1); // copy the original list and skip the first argument if this was the format string #ifdef R__VA_COPY va_end(ap); R__VA_COPY(ap, bap); #else - gAliHLTLoggingTarget[gAliHLTLoggingTarget.GetSize()-1]=0; + fgAliHLTLoggingTarget[fgAliHLTLoggingTarget.GetSize()-1]=0; break; #endif //R__VA_COPY if (format==NULL) va_arg(ap, const char*); @@ -255,7 +290,7 @@ const char* AliHLTLogging::BuildLogString(const char *format, va_list ap) va_end(bap); #endif //R__VA_COPY - return gAliHLTLoggingTarget.GetArray(); + return fgAliHLTLoggingTarget.GetArray(); } int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, @@ -267,14 +302,12 @@ int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, if (iResult>0) { va_list args; va_start(args, format); - if (fLoggingFunc) { - iResult = (*fLoggingFunc)(NULL/*fParam*/, severity, origin, keyword, AliHLTLogging::BuildLogString(format, args )); + 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); @@ -283,7 +316,7 @@ int AliHLTLogging::Logging(AliHLTComponentLogSeverity severity, } int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity, - const char* origin_class, const char* origin_func, + const char* originClass, const char* originFunc, const char* file, int line, ... ) const { // see header file for class documentation @@ -291,29 +324,27 @@ int AliHLTLogging::LoggingVarargs(AliHLTComponentLogSeverity severity, if (file==NULL && line==0) { // this is currently just to get rid of the warning "unused parameter" } - int iResult=CheckFilter(severity); + int iResult=1; //CheckFilter(severity); // check moved to makro if (iResult>0) { const char* separator=""; TString origin; - if (origin_class) { - origin+=origin_class; + if (originClass) { + origin+=originClass; separator="::"; } - if (origin_func) { + if (originFunc) { origin+=separator; - origin+=origin_func; + origin+=originFunc; } va_list args; va_start(args, line); - if (fLoggingFunc) { - iResult=(*fLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); + if (fgLoggingFunc) { + iResult=(*fgLoggingFunc)(NULL/*fParam*/, severity, origin.Data(), GetKeyword(), AliHLTLogging::BuildLogString(NULL, args )); } else { -#ifndef NOALIROOT_LOGGING - if (fgUseAliLog) - iResult=AliMessage(severity, origin_class, origin_func, file, line, AliHLTLogging::BuildLogString(NULL, args )); + if (fgUseAliLog!=0 && fgAliLoggingFunc!=NULL) + iResult=(*fgAliLoggingFunc)(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); @@ -325,7 +356,7 @@ int AliHLTLogging::CheckFilter(AliHLTComponentLogSeverity severity) const { // see header file for class documentation - int iResult=severity==kHLTLogNone || (severity&fGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; + int iResult=severity==kHLTLogNone || (severity&fgGlobalLogFilter)>0 && (severity&fLocalLogFilter)>0; return iResult; } @@ -333,7 +364,14 @@ void AliHLTLogging::SetGlobalLoggingLevel(AliHLTComponentLogSeverity level) { // see header file for class documentation - fGlobalLogFilter=level; + fgGlobalLogFilter=level; +} + +AliHLTComponentLogSeverity AliHLTLogging::GetGlobalLoggingLevel() +{ + // see header file for class documentation + + return fgGlobalLogFilter; } void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level) @@ -342,3 +380,36 @@ void AliHLTLogging::SetLocalLoggingLevel(AliHLTComponentLogSeverity level) fLocalLogFilter=level; } + + +AliHLTComponentLogSeverity AliHLTLogging::GetLocalLoggingLevel() +{ + // see header file for class documentation + + return fLocalLogFilter; +} + +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; +}