00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _LOG4TANGO_LOGGER_H
00029 #define _LOG4TANGO_LOGGER_H
00030
00031
00032
00033
00034
00035
00036 #include <log4tango/Portability.hh>
00037 #include <log4tango/AppenderAttachable.hh>
00038 #include <log4tango/LoggingEvent.hh>
00039 #include <log4tango/Level.hh>
00040 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00041 # include <log4tango/LoggerStream.hh>
00042 #endif
00043
00044 namespace log4tango {
00045
00046 #ifdef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00047
00048
00049
00050 class LogStream;
00051 #endif
00052
00053
00054
00055
00056 class LOG4TANGO_EXPORT Logger : public AppenderAttachable
00057 {
00058 public:
00059
00065 Logger(const std::string& name,
00066 Level::Value level = Level::OFF);
00067
00071 virtual ~Logger();
00072
00077 inline const std::string& get_name() const {
00078 return _name;
00079 }
00080
00085 void set_level (Level::Value level);
00086
00091 inline Level::Value get_level() const {
00092 return _level;
00093 }
00094
00101 bool is_level_enabled (Level::Value level) const {
00102 return _level >= level;
00103 }
00104
00111 void log (Level::Value level,
00112 const char* string_format, ...);
00113
00119 inline void log (Level::Value level, const std::string& message)
00120 {
00121 if (is_level_enabled(level)) {
00122 log_unconditionally(level, message);
00123 }
00124 }
00125
00132 void log_unconditionally (Level::Value level,
00133 const char* string_format, ...);
00134
00140 void log_unconditionally (Level::Value level,
00141 const std::string& message);
00142
00148 void debug (const char* string_format, ...);
00149
00154 inline void debug (const std::string& message) {
00155 if (is_level_enabled(Level::DEBUG)) {
00156 log_unconditionally(Level::DEBUG, message);
00157 }
00158 }
00159
00164 inline bool is_debug_enabled (void) const {
00165 return is_level_enabled (Level::DEBUG);
00166 };
00167
00168 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00169
00173 inline LoggerStream debug_stream (void) {
00174 return LoggerStream(*this, Level::DEBUG, true);
00175 }
00176 #else
00177
00181 inline LogStream& debug_stream (void) {
00182 return *_log_streams[_DEBUG_STREAM_ID];
00183 }
00184 #endif
00185
00191 void info (const char* string_format, ...);
00192
00197 inline void info (const std::string& message) {
00198 if (is_level_enabled(Level::INFO)) {
00199 log_unconditionally(Level::INFO, message);
00200 }
00201 }
00202
00207 inline bool is_info_enabled (void) const {
00208 return is_level_enabled(Level::INFO);
00209 };
00210
00211 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00212
00216 inline LoggerStream info_stream (void) {
00217 return LoggerStream(*this, Level::INFO, true);
00218 }
00219 #else
00220
00224 inline LogStream& info_stream (void) {
00225 return *_log_streams[_INFO_STREAM_ID];
00226 }
00227 #endif
00228
00234 void warn (const char* string_format, ...);
00235
00240 inline void warn (const std::string& message) {
00241 if (is_level_enabled(Level::WARN)) {
00242 log_unconditionally(Level::WARN, message);
00243 }
00244 }
00245
00250 inline bool is_warn_enabled (void) const {
00251 return is_level_enabled(Level::WARN);
00252 };
00253
00254 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00255
00259 inline LoggerStream warn_stream (void) {
00260 return LoggerStream(*this, Level::WARN, true);
00261 };
00262 #else
00263
00267 inline LogStream& warn_stream (void) {
00268 return *_log_streams[_WARN_STREAM_ID];
00269 }
00270 #endif
00271
00277 void error (const char* string_format, ...);
00278
00283 inline void error (const std::string& message) {
00284 if (is_level_enabled(Level::ERROR)) {
00285 log_unconditionally(Level::ERROR, message);
00286 }
00287 }
00288
00293 inline bool is_error_enabled (void) const {
00294 return is_level_enabled(Level::ERROR);
00295 };
00296
00297 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00298
00302 inline LoggerStream error_stream (void) {
00303 return LoggerStream(*this, Level::ERROR, true);
00304 };
00305 #else
00306
00310 inline LogStream& error_stream (void) {
00311 return *_log_streams[_ERROR_STREAM_ID];
00312 }
00313 #endif
00314
00320 void fatal(const char* string_format, ...);
00321
00326 inline void fatal (const std::string& message) {
00327 if (is_level_enabled(Level::FATAL)) {
00328 log_unconditionally(Level::FATAL, message);
00329 }
00330 }
00331
00336 inline bool is_fatal_enabled (void) const {
00337 return is_level_enabled(Level::FATAL);
00338 };
00339
00340 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00341
00345 inline LoggerStream fatal_stream (void) {
00346 return LoggerStream(*this, Level::FATAL, true);
00347 };
00348 #else
00349
00353 inline LogStream& fatal_stream (void) {
00354 return *_log_streams[_FATAL_STREAM_ID];
00355 }
00356 #endif
00357
00358 #ifndef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00359
00365 inline LoggerStream get_stream (Level::Value level, bool filter = true) {
00366 return LoggerStream(*this, level, filter);
00367 }
00368 #endif
00369
00370 protected:
00371
00377 void call_appenders (const LoggingEvent& event);
00378
00379
00380 private:
00381
00382 #ifdef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00383
00384 enum {
00385 _FATAL_STREAM_ID = 0,
00386 _ERROR_STREAM_ID = 1,
00387 _WARN_STREAM_ID = 2,
00388 _INFO_STREAM_ID = 3,
00389 _DEBUG_STREAM_ID = 4
00390 };
00391 #endif
00392
00394 const std::string _name;
00395
00397 Level::Value _level;
00398
00399 #ifdef LOG4TANGO_LOGGERS_USE_LOGSTREAM
00400
00401 LogStream *_log_streams[5];
00402 #endif
00403
00404
00405 Logger (const Logger&);
00406 Logger& operator= (const Logger&);
00407 };
00408
00409 }
00410
00411 #endif // _LOG4TANGO_LOGGER_H