Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
AppLog Class Reference

Application logger is a class that implements a logger that can be used by applications to save log file somewhere on the system. More...

#include <applog.h>

Inheritance diagram for AppLog:
Inheritance graph
[legend]
Collaboration diagram for AppLog:
Collaboration graph
[legend]

Data Structures

class  Ident
 Ident class that represents module name. More...
 

Public Member Functions

 AppLog (const char *logFileName=NULL, bool logDirectly=false, bool usePipe=false)
 Constructor for a customized logger. More...
 
virtual ~AppLog ()
 Destructor. More...
 
void subscribe ()
 Subscribes the current thread to logger, it reserves thread safe buffer for it. More...
 
void unsubscribe ()
 Unsubscribes the current thread from logger. More...
 
void logFileName (const char *FileName, bool logDirectly=false, bool usePipe=false)
 Allows to set up ost::alog parameters. More...
 
void close (void)
 if logDirectly is set it closes the file. More...
 
void level (Slog::Level enable)
 Sets the log level. More...
 
void clogEnable (bool en=true)
 Enables clog output. More...
 
void slogEnable (bool en=true)
 Enables slog output for error level messages. More...
 
void identLevel (const char *ident, Slog::Level level)
 Sets the level for that ident. More...
 
void open (const char *ident)
 Opens the file if not already and sets ident. More...
 
virtual int overflow (int c)
 stream overflow() overload. More...
 
virtual int sync ()
 stream sync() overload More...
 
AppLogoperator() (const char *ident, Slog::Level level=Slog::levelError)
 operator to change ident and log level More...
 
AppLogoperator() (Ident &ident)
 operator to change ident More...
 
AppLogoperator() (Slog::Level level)
 operator to change logging level More...
 
AppLogoperator<< (AppLog &(*pfManipulator)(AppLog &))
 manipulator operator, to change print levels. More...
 
AppLogoperator<< (ostream &(*pfManipulator)(ostream &))
 manipulator operator, to use ostream manipulators (i.e. More...
 
AppLogoperator<< (Ident &ident)
 operator << More...
 
AppLogwarn (void)
 warn level More...
 
AppLogerror (void)
 error level More...
 
AppLogdebug (void)
 debug level More...
 
AppLogemerg (void)
 emerg level More...
 
AppLogalert (void)
 alert level More...
 
AppLogcritical (void)
 critical level More...
 
AppLognotice (void)
 notice level More...
 
AppLoginfo (void)
 info level More...
 

Static Public Member Functions

static Slog::Level levelTranslate (string name)
 Translates level from string to Slog::Level, useful for configuration files for instance. More...
 

Protected Member Functions

void writeLog (bool endOfLine=true)
 

Protected Attributes

AppLogPrivate * d
 

Static Protected Attributes

static map< string, Slog::Level > * assoc
 

Friends

ostream & operator<< (ostream &out, AppLog &al)
 

Detailed Description

Application logger is a class that implements a logger that can be used by applications to save log file somewhere on the system.

It uses ost::slog to write to syslog and std::clog to write to standard output.

It provides either a stream oriented logger or a old printf style one.

It can be used to log directly on a file or in a spooler like way. Latter uses a ost::ThreadQueue to implement a thread safe access to logger.

It provides a global stream variable called ost::alog.

It provides an AppLog::Ident class that represents a module name for instance that can be used to tag logs. Logging levels are the same defined into ost::Slog: Slog::levelEmergency Slog::levelAlert Slog::levelCritical Slog::levelError Slog::levelWarning Slog::levelNotice Slog::levelInfo Slog::levelDebugfrom.

Example of usage: alog << mod_name << debug << "Hello world!" << std::endl;

Definition at line 173 of file applog.h.

Constructor & Destructor Documentation

AppLog::AppLog ( const char *  logFileName = NULL,
bool  logDirectly = false,
bool  usePipe = false 
)

Constructor for a customized logger.

Parameters
logFileNamelog file name.
logDirectlytrue to write directly to file, false to use a spooler like logger.
usePipetrue to use pipe instead of file, false otherwise
virtual AppLog::~AppLog ( )
virtual

Destructor.

Member Function Documentation

AppLog& AppLog::alert ( void  )
inline

alert level

Returns
application logger stream

Definition at line 472 of file applog.h.

void AppLog::clogEnable ( bool  en = true)

Enables clog output.

Parameters
entrue to enable clog output.
void AppLog::close ( void  )

if logDirectly is set it closes the file.

AppLog& AppLog::critical ( void  )
inline

critical level

Returns
application logger stream

Definition at line 479 of file applog.h.

AppLog& AppLog::debug ( void  )
inline

debug level

Returns
application logger stream

Definition at line 458 of file applog.h.

AppLog& AppLog::emerg ( void  )
inline

emerg level

Returns
application logger stream

Definition at line 465 of file applog.h.

AppLog& AppLog::error ( void  )
inline

error level

Returns
application logger stream

Definition at line 451 of file applog.h.

void AppLog::identLevel ( const char *  ident,
Slog::Level  level 
)

Sets the level for that ident.

Parameters
identident (module name for instance).
levellevel
AppLog& AppLog::info ( void  )
inline

info level

Returns
application logger stream

Definition at line 493 of file applog.h.

void AppLog::level ( Slog::Level  enable)

Sets the log level.

Parameters
enablelog level.
static Slog::Level AppLog::levelTranslate ( string  name)
inlinestatic

Translates level from string to Slog::Level, useful for configuration files for instance.

Valid level names are: "emerg" for Slog::levelEmergency "alert" for Slog::levelAlert "critical" for Slog::levelCritical "error" for Slog::levelError "warn" for Slog::levelWarning "notice" for Slog::levelNotice "info" for Slog::levelInfo "debug" for Slog::levelDebug

Parameters
nameSlog Level name
Returns
Slog level value

Definition at line 511 of file applog.h.

void AppLog::logFileName ( const char *  FileName,
bool  logDirectly = false,
bool  usePipe = false 
)

Allows to set up ost::alog parameters.

Parameters
FileNamelog file name.
logDirectlytrue to write directly to file, false to use a spooler like logger.
usePipetrue to use pipe instead of file, false otherwise
AppLog& AppLog::notice ( void  )
inline

notice level

Returns
application logger stream

Definition at line 486 of file applog.h.

void AppLog::open ( const char *  ident)

Opens the file if not already and sets ident.

Parameters
identmodule name for instance.
AppLog& AppLog::operator() ( const char *  ident,
Slog::Level  level = Slog::levelError 
)

operator to change ident and log level

Parameters
identident (module name for instance)
levelnew log level
Returns
application logger stream
AppLog& AppLog::operator() ( Ident ident)
inline

operator to change ident

Parameters
identident (module name for instance)
Returns
application logger stream

Definition at line 396 of file applog.h.

AppLog& AppLog::operator() ( Slog::Level  level)

operator to change logging level

Parameters
levelnew log level
Returns
application logger stream
AppLog& AppLog::operator<< ( AppLog &(*)(AppLog &)  pfManipulator)

manipulator operator, to change print levels.

Parameters
(*pfManipulator)(AppLog &)
Returns
application logger stream
AppLog& AppLog::operator<< ( ostream &(*)(ostream &)  pfManipulator)

manipulator operator, to use ostream manipulators (i.e.

std::endl,...)

Parameters
(*pfManipulator)(AppLog &)
Returns
application logger stream
AppLog& AppLog::operator<< ( Ident ident)
inline

operator <<

Parameters
identmodule name for instance.
Returns
application logger stream

Definition at line 433 of file applog.h.

virtual int AppLog::overflow ( int  c)
virtual

stream overflow() overload.

Parameters
ccharacter to be managed
Returns
c
void AppLog::slogEnable ( bool  en = true)

Enables slog output for error level messages.

Parameters
entrue to enable slog output.
void AppLog::subscribe ( )

Subscribes the current thread to logger, it reserves thread safe buffer for it.

virtual int AppLog::sync ( )
virtual

stream sync() overload

void AppLog::unsubscribe ( )

Unsubscribes the current thread from logger.

AppLog& AppLog::warn ( void  )
inline

warn level

Returns
application logger stream

Definition at line 444 of file applog.h.

void AppLog::writeLog ( bool  endOfLine = true)
protected

Friends And Related Function Documentation

ostream& operator<< ( ostream &  out,
AppLog al 
)
friend

Definition at line 423 of file applog.h.

Field Documentation

map<string, Slog::Level>* AppLog::assoc
staticprotected

Definition at line 179 of file applog.h.

AppLogPrivate* AppLog::d
protected

Definition at line 177 of file applog.h.


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