00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00026 #ifndef LIMAL_LOGGER_HPP
00027 #define LIMAL_LOGGER_HPP
00028
00029 #include <blocxx/Array.hpp>
00030 #include <blocxx/String.hpp>
00031 #include <blocxx/StringStream.hpp>
00032 #include <blocxx/LogConfig.hpp>
00033 #include <blocxx/Logger.hpp>
00034 #include <blocxx/CommonFwd.hpp>
00035 #include <blocxx/LogAppender.hpp>
00036 #include <blocxx/AppenderLogger.hpp>
00037 #include <limal/config.h>
00038
00039
00055 #define LIMAL_LOG(logger, level, message) \
00056 do \
00057 { \
00058 int err = errno; \
00059 if( (logger).isEnabledFor(level)) \
00060 { \
00061 (logger).logMessage((level), (message), \
00062 __FILE__, __LINE__, \
00063 BLOCXX_LOGGER_PRETTY_FUNCTION); \
00064 } \
00065 errno = err; \
00066 } while(0) // note the missing semicolon
00067
00068
00084 #define LIMAL_SLOG(logger, level, message) \
00085 do \
00086 { \
00087 int err = errno; \
00088 if( (logger).isEnabledFor(level)) \
00089 { \
00090 blocxx::OStringStream _buf; \
00091 _buf << message; \
00092 (logger).logMessage((level), _buf.toString(), \
00093 __FILE__, __LINE__, \
00094 BLOCXX_LOGGER_PRETTY_FUNCTION); \
00095 } \
00096 errno = err; \
00097 } while(0) // note the missing semicolon
00098
00099
00114 #define LIMAL_LOG_FATAL(logger, logMessage) \
00115 LIMAL_LOG(logger, blocxx::E_FATAL_ERROR_LEVEL, logMessage)
00116
00117 #define LIMAL_SLOG_FATAL(logger, logMessage) \
00118 LIMAL_SLOG(logger, blocxx::E_FATAL_ERROR_LEVEL, logMessage)
00119
00120
00135 #define LIMAL_LOG_ERROR(logger, logMessage) \
00136 LIMAL_LOG(logger, blocxx::E_ERROR_LEVEL, logMessage)
00137
00138 #define LIMAL_SLOG_ERROR(logger, logMessage) \
00139 LIMAL_SLOG(logger, blocxx::E_ERROR_LEVEL, logMessage)
00140
00141
00156 #define LIMAL_LOG_INFO(logger, logMessage) \
00157 LIMAL_LOG(logger, blocxx::E_INFO_LEVEL, logMessage)
00158
00159 #define LIMAL_SLOG_INFO(logger, logMessage) \
00160 LIMAL_SLOG(logger, blocxx::E_INFO_LEVEL, logMessage)
00161
00162
00177 #define LIMAL_LOG_DEBUG(logger, logMessage) \
00178 LIMAL_LOG(logger, blocxx::E_DEBUG_LEVEL, logMessage)
00179
00180 #define LIMAL_SLOG_DEBUG(logger, logMessage) \
00181 LIMAL_SLOG(logger, blocxx::E_DEBUG_LEVEL, logMessage)
00182
00183
00184 namespace LIMAL_NAMESPACE
00185 {
00186
00275 class Logger
00276 {
00277 public:
00288 typedef blocxx::ELogLevel ELogLevel;
00289
00322 static blocxx::LoggerRef createCerrLogger(
00323 const blocxx::String &component,
00324 const blocxx::Array<blocxx::String> &components,
00325 const blocxx::Array<blocxx::String> &categories,
00326 const blocxx::String &messageFormat
00327 );
00328
00360 static blocxx::LoggerRef createSyslogLogger(
00361 const blocxx::String &component,
00362 const blocxx::Array<blocxx::String> &components,
00363 const blocxx::Array<blocxx::String> &categories,
00364 const blocxx::String &messageFormat,
00365 const blocxx::String &identity,
00366 const blocxx::String &facility
00367 );
00368
00369
00404 static blocxx::LoggerRef createFileLogger(
00405 const blocxx::String &component,
00406 const blocxx::Array<blocxx::String> &components,
00407 const blocxx::Array<blocxx::String> &categories,
00408 const blocxx::String &messageFormat,
00409 const blocxx::String &filename,
00410 blocxx::UInt64 maxLogFileSize = 0,
00411 blocxx::UInt32 maxBackupIndex = 0
00412 );
00413
00443 static blocxx::LoggerRef createNullLogger(
00444 const blocxx::String &component,
00445 const blocxx::Array<blocxx::String> &components,
00446 const blocxx::Array<blocxx::String> &categories,
00447 const blocxx::String &messageFormat
00448 );
00449
00458 Logger(const blocxx::String &component = "");
00459
00460
00464 ~Logger();
00465
00466
00474 inline static bool
00475 setDefaultLogger(const blocxx::LoggerRef &ref)
00476 {
00477 return limal::Logger::setDefaultFromLoggerRef(ref);
00478 }
00479
00489 inline static bool
00490 setThreadLogger(const blocxx::LoggerRef &ref)
00491 {
00492 return limal::Logger::setThreadFromLoggerRef(ref);
00493 }
00494
00499 inline static blocxx::LoggerRef getDefaultLogger()
00500 {
00501 return limal::Logger::getDefaultAsLoggerRef();
00502 }
00503
00510 inline static blocxx::LoggerRef getCurrentLogger()
00511 {
00512 return limal::Logger::getCurrentAsLoggerRef();
00513 }
00514
00526 void
00527 logMessage(ELogLevel level,
00528 const blocxx::String &message,
00529 const char *filename = 0,
00530 int fileline = -1,
00531 const char *methodname = 0) const;
00532
00533
00545 void
00546 logMessage(const blocxx::String &category,
00547 const blocxx::String &message,
00548 const char *filename = 0,
00549 int fileline = -1,
00550 const char *methodname = 0) const;
00551
00552
00559 bool
00560 isEnabledFor(const ELogLevel level) const;
00561
00562
00570 bool
00571 isEnabledFor(const blocxx::String &category) const;
00572
00573
00574 private:
00575 static bool setDefaultFromLoggerRef(const blocxx::LoggerRef &ref);
00576 static bool setThreadFromLoggerRef(const blocxx::LoggerRef &ref);
00577 static blocxx::LoggerRef getDefaultAsLoggerRef();
00578 static blocxx::LoggerRef getCurrentAsLoggerRef();
00579
00580 blocxx::String m_component;
00581
00582 };
00583
00584
00585 }
00586
00587
00588 #endif // LIMAL_LOGGER_HPP
00589
00590