Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LOGGING_LOG4CPP_H_
00025 #define LOGGING_LOG4CPP_H_
00026
00027 #include "loggingACSCategory.h"
00028 #include "logging_idlC.h"
00029
00030 #include <log4cpp/LayoutAppender.hh>
00031 #include <ace/Singleton.h>
00032 #include <ace/Synch.h>
00033 #include <orbsvcs/CosNamingC.h>
00034
00035 #include "loggingBaseLog.h"
00036
00037 #ifndef LM_DELOUSE
00038 #define LM_DELOUSE 010000U
00039 #endif
00040
00041 namespace logging {
00042
00043 struct BasicLogInfo {
00044 log4cpp::Priority::PriorityLevel priority;
00045 std::string message;
00046 };
00047
00048 class Logger {
00049 public:
00050
00051 Logger();
00052 ~Logger();
00053
00054 ACSCategory* getLogger(const std::string& loggerName);
00055 ACSCategory* getGlobalLogger();
00056 ACSCategory* getStaticLogger();
00057
00058 void enableRemoteAppender(unsigned long cacheSize = 100,
00059 unsigned int autoFlushTimeoutSec = 3,
00060 Logging::AcsLogService_ptr loggingService = Logging::AcsLogService::_nil(),
00061 CosNaming::NamingContext_ptr namingService = CosNaming::NamingContext::_nil(),
00062 int maxLogsPerSecond = -1);
00063 void enableSyslogAppender();
00064
00065 void setLogLevels(const std::string& loggerName, log4cpp::Priority::PriorityLevel remote, log4cpp::Priority::PriorityLevel local);
00066
00067 static BasicLogInfo formatLog(log4cpp::Priority::PriorityLevel priority, const char *fmt, ...)
00068 #if defined(__GNUC__)
00069 __attribute__ ((format (printf, 2, 3)))
00070 #endif
00071 ;
00072 static BasicLogInfo formatLog(ACE_Log_Priority priority, const char *fmt, ...)
00073 #if defined(__GNUC__)
00074 __attribute__ ((format (printf, 2, 3)))
00075 #endif
00076 ;
00077 static BasicLogInfo formatLog(unsigned int priority, const char *fmt, ...)
00078 #if defined(__GNUC__)
00079 __attribute__ ((format (printf, 2, 3)))
00080 #endif
00081 ;
00082
00083 private:
00084 bool remoteAppenderEnabled;
00085 bool syslogAppenderEnabled;
00086 unsigned int localLogLevel;
00087 unsigned int remoteLogLevel;
00088 unsigned int syslogLogLevel;
00089
00090 unsigned long cacheSize;
00091 unsigned int autoFlushTimeoutSec;
00092 Logging::AcsLogService_ptr loggingService;
00093 CosNaming::NamingContext_ptr namingService;
00094 int maxLogsPerSecond;
00095
00096 ACE_Thread_Mutex initMutex;
00097 ACSCategory* initLogger(const std::string& loggerName);
00098 };
00099
00100 class LogTrace {
00101 public:
00102 LogTrace (ACSCategory* logger, const std::string &method,
00103 const std::string &file, const unsigned long line);
00104 LogTrace (ACSCategory* logger, const std::string &method);
00105 ~LogTrace();
00106
00107 private:
00108 ACSCategory* logger;
00109 const std::string method;
00110 const std::string file;
00111 const unsigned long line;
00112 };
00113
00114 log4cpp::Priority::PriorityLevel convertPriority(unsigned int logLevel);
00115 log4cpp::Priority::PriorityLevel convertPriority(ACE_Log_Priority logLevel);
00116 log4cpp::Priority::PriorityLevel convertPriority(Logging::BaseLog::Priority logLevel);
00117 log4cpp::Priority::PriorityLevel convertPriority(AcsLogLevels::logLevelValue logLevel);
00118 }
00119
00120 #define LOGGER_FACTORY ACE_Singleton<logging::Logger, ACE_Null_Mutex>::instance()
00121 #endif