MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Logger Class Reference

#include <Logger.hpp>

Inheritance diagram for Logger:

Public Types

enum  LoggerLevel {
  LL_ON, LL_DEBUG, LL_INFO, LL_WARNING,
  LL_ERROR, LL_CRITICAL, LL_ALERT, LL_ALL
}

Public Member Functions

 Logger ()
virtual ~Logger ()
void setCategory (const char *pCategory)
bool createConsoleHandler (NdbOut &out=ndbout)
void removeConsoleHandler ()
bool createEventLogHandler (const char *source_name)
bool createFileHandler (char *filename=0)
void removeFileHandler ()
bool createSyslogHandler ()
void removeSyslogHandler ()
bool addHandler (LogHandler *pHandler)
bool addHandler (const BaseString &logstring, int *err, int len, char *errStr)
bool removeHandler (LogHandler *pHandler)
void removeAllHandlers ()
bool isEnable (LoggerLevel logLevel) const
void enable (LoggerLevel logLevel)
void enable (LoggerLevel fromLogLevel, LoggerLevel toLogLevel)
void disable (LoggerLevel logLevel)
virtual void alert (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void alert (BaseString &pMsg) const
virtual void critical (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void critical (BaseString &pMsg) const
virtual void error (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void error (BaseString &pMsg) const
virtual void warning (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void warning (BaseString &pMsg) const
virtual void info (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void info (BaseString &pMsg) const
virtual void debug (const char *pMsg,...) const ATTRIBUTE_FORMAT(printf
virtual void virtual void debug (BaseString &pMsg) const
virtual void setRepeatFrequency (unsigned val)

Static Public Attributes

static const char * LoggerLevelNames []

Protected Member Functions

void log (LoggerLevel logLevel, const char *msg, va_list ap) const

Protected Attributes

NdbMutex * m_mutex

Detailed Description

Logger should be used whenver you need to log a message like general information or debug messages. By creating/adding different log handlers, a single log message can be sent to different outputs (stdout, file or syslog).

Each log entry is created with a log level (or severity) which is used to identity the type of the entry, e.g., if it is a debug or an error message.

Example of a log entry:

09:17:39 2002-03-13 [myLogger] INFO – Local checkpoint started.

HOW TO USE

1) Create a new instance of the Logger.

Logger myLogger = new Logger();

2) Add the log handlers that you want, i.e., where the log entries should be written/shown.

myLogger->createConsoleHandler(); // Output to console/stdout myLogger->addHandler(new FileLogHandler("mylog.txt")); // use mylog.txt

3) Tag each log entry with a category/name.

myLogger->setCategory("myLogger");

4) Start log messages.

myLogger->alert("T-9 to lift off");
myLogger->info("Here comes the sun, la la"); 
myLogger->debug("Why does this not work!!!, We should not be here...")

5) Log only debug messages.

myLogger->enable(Logger::LL_DEBUG);

6) Log only ALERTS and ERRORS.

myLogger->enable(Logger::LL_ERROR, Logger::LL_ALERT);

7) Do not log any messages.

myLogger->disable(Logger::LL_ALL);

LOG LEVELS (Matches the severity levels of syslog)

 ALERT           A condition  that  should  be  corrected
                 immediately,  such as a corrupted system
                 database.
 CRITICAL        Critical conditions, such as hard device
                 errors.
 ERROR           Errors.
 WARNING         Warning messages.
 INFO            Informational messages.
 DEBUG           Messages that contain  information  nor-
                 mally  of use only when debugging a pro-
                 gram.
Version
#@
Id:
Logger.hpp,v 1.7 2003/09/01 10:15:53 innpeno Exp

Definition at line 102 of file Logger.hpp.

Member Enumeration Documentation

The log levels. NOTE: Could not use the name LogLevel since it caused conflicts with another class.

Definition at line 108 of file Logger.hpp.

Constructor & Destructor Documentation

Logger::Logger ( )

Default constructor.

Definition at line 42 of file Logger.cpp.

Here is the call graph for this function:

Logger::~Logger ( )
virtual

Destructor.

Definition at line 56 of file Logger.cpp.

Here is the call graph for this function:

Member Function Documentation

bool Logger::addHandler ( LogHandler pHandler)

Add a new log handler.

Parameters
pHandlera log handler.
Returns
true if successful.

Definition at line 195 of file Logger.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool Logger::addHandler ( const BaseString logstring,
int *  err,
int  len,
char *  errStr 
)

Add a new handler

Parameters
logstringstring describing the handler to add
errOS errno in event of error
lenmax length of errStr buffer
errStrlogger error string in event of error

Definition at line 214 of file Logger.cpp.

Here is the call graph for this function:

void Logger::alert ( const char *  pMsg,
  ... 
) const
virtual

Log an alert message.

Parameters
pMsgthe message.

Definition at line 370 of file Logger.cpp.

Here is the caller graph for this function:

bool Logger::createConsoleHandler ( NdbOut &  out = ndbout)

Create a default handler that logs to the console/stdout.

Returns
true if successful.

Definition at line 72 of file Logger.cpp.

Here is the call graph for this function:

bool Logger::createEventLogHandler ( const char *  source_name)

Create a default handler that logs to the Windows event log with source component set to source_name

NOTE! Can only be created on Windows.

Returns
true if successful.

Definition at line 104 of file Logger.cpp.

Here is the call graph for this function:

bool Logger::createFileHandler ( char *  filename = 0)

Create a default handler that logs to a file called logger.log.

Returns
true if successful.

Definition at line 126 of file Logger.cpp.

Here is the call graph for this function:

bool Logger::createSyslogHandler ( )

Create a default handler that logs to the syslog.

Returns
true if successful.

Definition at line 159 of file Logger.cpp.

Here is the call graph for this function:

void Logger::critical ( const char *  pMsg,
  ... 
) const
virtual

Log a critical message.

Parameters
pMsgthe message.

Definition at line 379 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::debug ( const char *  pMsg,
  ... 
) const
virtual

Log a debug message.

Parameters
pMsgthe message.

Definition at line 413 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::disable ( LoggerLevel  logLevel)

Disable log level.

Parameters
logLeveldisable log level.

Definition at line 353 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::enable ( LoggerLevel  logLevel)

Enable the specified log level.

Parameters
logLevelthe loglevel to enable.

Definition at line 319 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::enable ( LoggerLevel  fromLogLevel,
LoggerLevel  toLogLevel 
)

Enable log levels.

Parameters
fromLogLevelenable from log level.
toLogLevelenable to log level.

Definition at line 336 of file Logger.cpp.

void Logger::error ( const char *  pMsg,
  ... 
) const
virtual

Log an error message.

Parameters
pMsgthe message.

Definition at line 387 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::info ( const char *  pMsg,
  ... 
) const
virtual

Log an info message.

Parameters
pMsgthe message.

Definition at line 404 of file Logger.cpp.

Here is the caller graph for this function:

bool Logger::isEnable ( LoggerLevel  logLevel) const

Returns true if the specified log level is enabled.

Returns
true if enabled.

Definition at line 305 of file Logger.cpp.

void Logger::removeAllHandlers ( )

Remove all log handlers.

Definition at line 294 of file Logger.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Logger::removeConsoleHandler ( )

Remove the default console handler.

Definition at line 94 of file Logger.cpp.

Here is the call graph for this function:

void Logger::removeFileHandler ( )

Remove the default file handler.

Definition at line 149 of file Logger.cpp.

Here is the call graph for this function:

bool Logger::removeHandler ( LogHandler pHandler)

Remove a log handler.

Parameters
pHandlerlog handler to remove.
Returns
true if successful.

Definition at line 274 of file Logger.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void Logger::removeSyslogHandler ( )

Remove the default syslog handler.

Definition at line 185 of file Logger.cpp.

Here is the call graph for this function:

void Logger::setCategory ( const char *  pCategory)

Set a category/name that each log entry will have.

Parameters
pCategorythe category.

Definition at line 65 of file Logger.cpp.

Here is the caller graph for this function:

void Logger::warning ( const char *  pMsg,
  ... 
) const
virtual

Log a warning message.

Parameters
pMsgthe message.

Definition at line 395 of file Logger.cpp.

Here is the caller graph for this function:

Member Data Documentation

const char * Logger::LoggerLevelNames
static
Initial value:
{ "ON ",
"DEBUG ",
"INFO ",
"WARNING ",
"ERROR ",
"CRITICAL",
"ALERT ",
"ALL "
}

String representation of the the log levels.

Definition at line 114 of file Logger.hpp.


The documentation for this class was generated from the following files: