Log Class Reference

Class to handle loging. More...

#include <log.h>

Collaboration diagram for Log:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Log ()
void die (const char *s)
 Write message and kills program.
void die ()
 Kill the program.
void exit_failure (const char *s)
void exit_failure (const char *s, int errorcode)
void init (const char *file, bool tostderr)
void message (int level, const char *s)
void message (int level, std::string &s)
void debug (const char *s)
void debug (string &s)
void set_loglevel (int level)
void perror (const char *s)
template<class T>
Logoperator<< (const T &t)
Logoperator<< (ostream &(*op)(ostream &))
Logdevnull ()
Logtrace ()
Logdebug ()
Loginfo ()
Logwarning ()
Logerror ()
void setAcceptor (LogAcceptor *la)
 Set actual acceptor. May be 0 to set empty acceptor.

Private Member Functions

Logtime ()

Private Attributes

LogAcceptormLogAcceptor
 may be NULL
ofstream m_logfile
 log file
int m_level
 current log level
int m_min_level
 minimal level to log
bool m_tostderr
 if true, the loging goes to stderr also

Detailed Description

Class to handle loging.

Provides loging to file and loging to stderr. If you want to use main log, use macros like LOGD, LOGE,... You may use this class also to create special custom log.

Using TRACE macros minihowto. First when you want to see trace output in your log files you need to define WANT_TRACE. It is good idea to define at the beginnning of each cpp file. It if then easy to select what trace you want to see and you don't have to reedit too many sources / you don't have too search too large logfile. The macros: TIN you may write this macro at the beggining of function. It produce message that execution entered the function ald also produce message when execution leave the function (The leave part is automatic. You don't need to write anything else) TVARIABLE(v) print message to log that varibale v has value v. Both name and value are printed. TPOINT Write mark to log that execution passed this point TPOINTS(s) Same as TPOINT but also add string message s LOGT return stream with level set to TRACE. So you may use operator << and write to stream anything you want. When tracing is disabled LOGT return stream with log level set to devnull so no output will be produced.

Definition at line 115 of file log.h.


Constructor & Destructor Documentation

Log::Log  ) 
 

Definition at line 50 of file log.cpp.

References LOG_LEVEL_INFO, LOG_LEVEL_TRACE, m_min_level, m_tostderr, and mLogAcceptor.


Member Function Documentation

Log& Log::debug  )  [inline]
 

Definition at line 241 of file log.h.

References LOG_LEVEL_DEBUG, m_level, and time().

Referenced by debug().

Here is the call graph for this function:

void Log::debug string &  s  )  [inline]
 

Write message with debug level. '
' will be added at the end of message.

Parameters:
s text of message

Definition at line 187 of file log.h.

References debug().

Here is the call graph for this function:

void Log::debug const char *  s  )  [inline]
 

Write message with debug level. '
' will be added at the end of message.

Parameters:
s text of message

Definition at line 180 of file log.h.

References debug().

Here is the call graph for this function:

Log& Log::devnull  )  [inline]
 

Definition at line 239 of file log.h.

References LOG_LEVEL_DEVNULL, and m_level.

void Log::die  ) 
 

Kill the program.

Write message die. This call never return.

Definition at line 68 of file log.cpp.

Referenced by die(), exit_failure(), and init().

void Log::die const char *  s  ) 
 

Write message and kills program.

This call never return.

Parameters:
s string to print

Definition at line 79 of file log.cpp.

References die(), and error().

Referenced by DIE(), get_bool(), get_double(), and get_long().

Here is the call graph for this function:

Log& Log::error  )  [inline]
 

Definition at line 244 of file log.h.

References LOG_LEVEL_ERROR, m_level, and time().

Referenced by die(), exit_failure(), get_bool(), get_double(), get_long(), and perror().

Here is the call graph for this function:

void Log::exit_failure const char *  s,
int  errorcode
 

Write message and explanation of errorcode.

Parameters:
s message before explanation of error code.
errorcode errorcode to explain

Definition at line 96 of file log.cpp.

References die(), and error().

Here is the call graph for this function:

void Log::exit_failure const char *  s  ) 
 

Write message s and add explanation of current errno

Parameters:
s message before explanation of errno

Definition at line 90 of file log.cpp.

Log& Log::info  )  [inline]
 

Definition at line 242 of file log.h.

References LOG_LEVEL_INFO, m_level, and time().

Here is the call graph for this function:

void Log::init const char *  file,
bool  tostderr
 

Inicialize the logging system. Opens log file. Also connect to syslog.

Parameters:
file name of file where to write. The program DIE if the file can't be opened.
tostderr if true, messages are send to stderr also

Definition at line 114 of file log.cpp.

References die(), LOGE, m_logfile, and m_tostderr.

Referenced by ApplicationServer::init(), and ApplicationClient::init().

Here is the call graph for this function:

void Log::message int  level,
std::string &  s
 

Write message with loglevel. '
' will be added at the end of message.

Parameters:
level loging level for this message
s text of message

Definition at line 139 of file log.cpp.

References m_level.

void Log::message int  level,
const char *  s
 

Write message with loglevel. '
' will be added at the end of message.

Parameters:
level loging level for this message
s text of message

Definition at line 132 of file log.cpp.

Log& Log::operator<< ostream &(*)(ostream &)  op  )  [inline]
 

Operator for manipulators - like flush, endl,.. Also works with formating manipulators.

Parameters:
op manipulator

Definition at line 226 of file log.h.

References LOG_LEVEL_DEVNULL, m_level, m_logfile, m_min_level, m_tostderr, and mLogAcceptor.

template<class T>
Log& Log::operator<< const T &  t  )  [inline]
 

Operator for writing to log. You should use this operator if you need to write anything to logfile.

Parameters:
t what you want to write

Definition at line 206 of file log.h.

References LOG_LEVEL_WARNING, m_level, m_logfile, m_min_level, m_tostderr, and mLogAcceptor.

void Log::perror const char *  s  ) 
 

Behaves same as perror function but the output is better stylised.

Definition at line 147 of file log.cpp.

References error().

Referenced by try_get_double(), and try_get_long().

Here is the call graph for this function:

void Log::set_loglevel int  level  )  [inline]
 

Definition at line 193 of file log.h.

References m_min_level.

Referenced by ApplicationServer::init(), and ApplicationClient::init().

void Log::setAcceptor LogAcceptor la  )  [inline]
 

Set actual acceptor. May be 0 to set empty acceptor.

Parameters:
la new log acceptor

Definition at line 251 of file log.h.

References mLogAcceptor.

Referenced by Console::clean(), and Console::registerLog().

Log & Log::time  )  [private]
 

Write current time in the log file

Definition at line 165 of file log.cpp.

References LOG_LEVEL_ERROR, and m_level.

Referenced by debug(), error(), info(), trace(), and warning().

Log& Log::trace  )  [inline]
 

Definition at line 240 of file log.h.

References LOG_LEVEL_TRACE, m_level, and time().

Referenced by AutoTraceOut::~AutoTraceOut().

Here is the call graph for this function:

Log& Log::warning  )  [inline]
 

Definition at line 243 of file log.h.

References LOG_LEVEL_WARNING, m_level, and time().

Here is the call graph for this function:


Member Data Documentation

int Log::m_level [private]
 

current log level

Definition at line 262 of file log.h.

Referenced by debug(), devnull(), error(), info(), message(), operator<<(), time(), trace(), and warning().

ofstream Log::m_logfile [private]
 

log file

Definition at line 260 of file log.h.

Referenced by init(), and operator<<().

int Log::m_min_level [private]
 

minimal level to log

Definition at line 264 of file log.h.

Referenced by Log(), operator<<(), and set_loglevel().

bool Log::m_tostderr [private]
 

if true, the loging goes to stderr also

Definition at line 266 of file log.h.

Referenced by init(), Log(), and operator<<().

LogAcceptor* Log::mLogAcceptor [private]
 

may be NULL

Definition at line 258 of file log.h.

Referenced by Log(), operator<<(), and setAcceptor().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:19:35 2006 for bjs by  doxygen 1.4.5