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
00274 class Logger
00275 {
00276 public:
00287 typedef blocxx::ELogLevel ELogLevel;
00288
00323 static blocxx::LoggerRef createCerrLogger(
00324 const blocxx::String &component,
00325 const blocxx::Array<blocxx::String> &components,
00326 const blocxx::Array<blocxx::String> &categories,
00327 const blocxx::String &messageFormat
00328 );
00329
00361 static blocxx::LoggerRef createSyslogLogger(
00362 const blocxx::String &component,
00363 const blocxx::Array<blocxx::String> &components,
00364 const blocxx::Array<blocxx::String> &categories,
00365 const blocxx::String &messageFormat,
00366 const blocxx::String &identity,
00367 const blocxx::String &facility
00368 );
00369
00370
00405 static blocxx::LoggerRef createFileLogger(
00406 const blocxx::String &component,
00407 const blocxx::Array<blocxx::String> &components,
00408 const blocxx::Array<blocxx::String> &categories,
00409 const blocxx::String &messageFormat,
00410 const blocxx::String &filename,
00411 blocxx::UInt64 maxLogFileSize = 0,
00412 blocxx::UInt32 maxBackupIndex = 0
00413 );
00414
00444 static blocxx::LoggerRef createNullLogger(
00445 const blocxx::String &component,
00446 const blocxx::Array<blocxx::String> &components,
00447 const blocxx::Array<blocxx::String> &categories,
00448 const blocxx::String &messageFormat
00449 );
00450
00459 Logger(const blocxx::String &component = "");
00460
00461
00465 ~Logger();
00466
00467
00475 inline static bool
00476 setDefaultLogger(const blocxx::LoggerRef &ref)
00477 {
00478 return blocxx::Logger::setDefaultLogger(ref);
00479 }
00480
00490 inline static bool
00491 setThreadLogger(const blocxx::LoggerRef &ref)
00492 {
00493 return blocxx::Logger::setThreadLogger(ref);
00494 }
00495
00500 inline static blocxx::LoggerRef getDefaultLogger()
00501 {
00502 return blocxx::Logger::getDefaultLogger();
00503 }
00504
00511 inline static blocxx::LoggerRef getCurrentLogger()
00512 {
00513 return blocxx::Logger::getCurrentLogger();
00514 }
00515
00527 void
00528 logMessage(ELogLevel level,
00529 const blocxx::String &message,
00530 const char *filename = 0,
00531 int fileline = -1,
00532 const char *methodname = 0) const;
00533
00534
00546 void
00547 logMessage(const blocxx::String &category,
00548 const blocxx::String &message,
00549 const char *filename = 0,
00550 int fileline = -1,
00551 const char *methodname = 0) const;
00552
00553
00560 bool
00561 isEnabledFor(const ELogLevel level);
00562
00563
00571 bool
00572 isEnabledFor(const blocxx::String &category);
00573
00574
00575 private:
00576 blocxx::String m_component;
00577
00578 };
00579
00580
00581 }
00582
00583
00584 #endif // LIMAL_LOGGER_HPP
00585
00586