l4snd::Logger Class Reference

Logger class. More...

Collaboration diagram for l4snd::Logger:

Collaboration graph
[legend]

List of all members.

Public Types

enum  Level {
  All = 00, Trace = 10, Debug = 20, Info = 30,
  Warning = 40, Error = 50, Fatal = 60, OFF = 90
}
 Logging threshold. More...

Public Member Functions

 Logger ()
 Construct logger.
virtual ~Logger ()
 Provide virtual destructor.
void setPrimaryAppender (Appender *app)
 Sets the primary appender.
AppendergetPrimaryAppender () const
 Gets the primary appender.
void setSecondaryAppender (Appender *app)
 Sets the secondary appender.
AppendergetSecondaryAppender () const
 Gets the secondary appender.
void setLevel (Level level)
 Sets the current log level.
Level getLevel () const
 Gets the current log level.
bool isLogged (Level level) const
 Tests the current log level.
bool isLocationInfoEnabled () const
 Tests if location info should be logged.
void setLocationInfoEnabled (bool enable)
 Enables logging of location information.
void log (Level level, std::string msg, std::string category="", const LocationInformation *info=0)
 Sends a message to the log.
void trace (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends a trace message to the log.
void debug (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends a debug message to the log.
void info (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends an information message to the log.
void warn (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends a warning message to the log.
void error (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends an error message to the log.
void fatal (std::string msg, std::string category="", const LocationInformation *info=0)
 Sends a fatal message to the log.
NDCndc ()
 Returns the nested diagnostics object.
MDCmdc ()
 Returns the nested diagnostics object.
Propertyproperty ()
 Returns the current property set.

Static Public Member Functions

static Loggerlogger ()
 Gets the default logger object.
static void initLogging (const std::string &appname, const std::string &hostname)
 Sets the default logger object.
static void initLogging (Appender *prim_app, Appender *sec_app)
 Sets the default logger object.
static LOG4SENDPP_INT64 currentTimeMillis ()
 The number of milliseconds elapsed from 1/1/1970 until logging event was created.

Classes

struct  DiagnosticInformation
 Keep additional diagnostic info. More...


Detailed Description

Logger class.

Definition at line 49 of file logger.h.


Member Enumeration Documentation

enum l4snd::Logger::Level

Logging threshold.

All actual levels equal to or higher than the threshold are logged.

Enumerator:
All  log everything
Trace  log program trace
Debug  log debug messages
Info  log general information
Warning  log warnings
Error  log errors
Fatal  log fatal messages
OFF  logging completely off

Definition at line 76 of file logger.h.


Member Function Documentation

Logger & l4snd::Logger::logger (  )  [static]

Gets the default logger object.

Returns:
reference to default logger

Definition at line 97 of file logger.cpp.

References initLogging().

void l4snd::Logger::initLogging ( const std::string &  appname,
const std::string &  hostname 
) [static]

Sets the default logger object.

Based on the appname a TcpIpAppender and a FileAppender are set as appenders. Targets are "localhost" and a file beginning with appname in the current directory.

Parameters:
appname name of the running application.
hostname name of the logging host (port is 4448)

Definition at line 80 of file logger.cpp.

Referenced by logger().

void l4snd::Logger::initLogging ( Appender prim_app,
Appender sec_app 
) [static]

Sets the default logger object.

Parameters:
prim_app pointer to new primary appender
sec_app pointer to new secondary appender

Definition at line 88 of file logger.cpp.

References setPrimaryAppender(), and setSecondaryAppender().

void l4snd::Logger::setPrimaryAppender ( Appender app  ) 

Sets the primary appender.

The primary appender is tested first for a working state. Should this fail the second appender is checked. The default logger has TcpIpAppender as primary and FileAppender as a fallback.

Parameters:
app pointer to appender object (takes ownership)

Definition at line 109 of file logger.cpp.

Referenced by initLogging().

Appender * l4snd::Logger::getPrimaryAppender (  )  const

Gets the primary appender.

Returns:
pointer to appender object

Definition at line 117 of file logger.cpp.

void l4snd::Logger::setSecondaryAppender ( Appender app  ) 

Sets the secondary appender.

See setPrimaryAppender .

Parameters:
app pointer to appender object (takes ownership)

Definition at line 123 of file logger.cpp.

Referenced by initLogging().

Appender * l4snd::Logger::getSecondaryAppender (  )  const

Gets the secondary appender.

Returns:
pointer to appender object

Definition at line 130 of file logger.cpp.

void l4snd::Logger::setLevel ( Level  level  ) 

Sets the current log level.

Messages are only logged if the level of the request if equal to or above this value.

Parameters:
level new log threshold

Definition at line 136 of file logger.cpp.

Referenced by Logger().

Logger::Level l4snd::Logger::getLevel (  )  const

Gets the current log level.

return current log threshold

Definition at line 142 of file logger.cpp.

bool l4snd::Logger::isLogged ( Level  level  )  const

Tests the current log level.

Parameters:
level log threshold
Returns:
true: level is above or equal to threshold

Definition at line 148 of file logger.cpp.

bool l4snd::Logger::isLocationInfoEnabled (  )  const

Tests if location info should be logged.

Diabling this part might increase performance

Returns:
true: log location info

Definition at line 154 of file logger.cpp.

void l4snd::Logger::setLocationInfoEnabled ( bool  enable  ) 

Enables logging of location information.

Diabling this part might increase performance

Parameters:
enable true: log location info

Definition at line 160 of file logger.cpp.

Referenced by Logger().

void l4snd::Logger::log ( Level  level,
std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends a message to the log.

Messages are only logged if the level of the request if equal to or above this value. To avoid runtime penalties you should check the level in advance with isLogged.

Parameters:
level log threshold
msg message to log
category message category
info pointer to information about the caller

Definition at line 238 of file logger.cpp.

References l4snd::Appender::append(), currentTimeMillis(), l4snd::Appender::isWorking(), and LOG4SENDPP_INT64.

Referenced by debug(), error(), fatal(), info(), trace(), and warn().

void l4snd::Logger::trace ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends a trace message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 167 of file logger.cpp.

References log(), and Trace.

void l4snd::Logger::debug ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends a debug message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 176 of file logger.cpp.

References Debug, and log().

void l4snd::Logger::info ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends an information message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 185 of file logger.cpp.

References Info, and log().

void l4snd::Logger::warn ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends a warning message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 194 of file logger.cpp.

References log(), and Warning.

void l4snd::Logger::error ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends an error message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 203 of file logger.cpp.

References Error, and log().

void l4snd::Logger::fatal ( std::string  msg,
std::string  category = "",
const LocationInformation info = 0 
)

Sends a fatal message to the log.

Parameters:
msg message to log
category message category
info pointer to information about the caller

Definition at line 212 of file logger.cpp.

References Fatal, and log().

NDC & l4snd::Logger::ndc (  ) 

Returns the nested diagnostics object.

Returns:
reference to NDC

Definition at line 220 of file logger.cpp.

MDC & l4snd::Logger::mdc (  ) 

Returns the nested diagnostics object.

Returns:
reference to MDC

Definition at line 226 of file logger.cpp.

Property & l4snd::Logger::property (  ) 

Returns the current property set.

Returns:
reference to property set

Definition at line 232 of file logger.cpp.

LOG4SENDPP_INT64 l4snd::Logger::currentTimeMillis (  )  [static]

The number of milliseconds elapsed from 1/1/1970 until logging event was created.

Returns:
current value of milliseconds

Definition at line 256 of file logger.cpp.

References LOG4SENDPP_INT64.

Referenced by log().


The documentation for this class was generated from the following files:
Generated on Sat Nov 24 14:41:25 2007 for log4sendpp by  doxygen 1.5.3