UCommon
ost::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>

Inherits streambuf, and ostream.

Data Structures

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

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

void writeLog (bool endOfLine=true)
 

Protected Attributes

AppLogPrivate * d
 

Static Protected Attributes

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

Friends

ostream & operator<< (ostream &os, 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()

ost::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

Member Function Documentation

◆ alert() [1/2]

void ost::AppLog::alert ( const char * format,
... )

alert level printf style method, provided for convenience.

Parameters
formatprintf format

◆ alert() [2/2]

AppLog & ost::AppLog::alert ( void )
inline

alert level

Returns
application logger stream

Definition at line 468 of file applog.h.

◆ clogEnable()

void ost::AppLog::clogEnable ( bool en = true)

Enables clog output.

Parameters
entrue to enable clog output.

◆ critical() [1/2]

void ost::AppLog::critical ( const char * format,
... )

critical level printf style method, provided for convenience.

Parameters
formatprintf format

◆ critical() [2/2]

AppLog & ost::AppLog::critical ( void )
inline

critical level

Returns
application logger stream

Definition at line 475 of file applog.h.

◆ debug() [1/2]

void ost::AppLog::debug ( const char * format,
... )

debug level printf style method, provided for convenience.

Parameters
formatprintf format

◆ debug() [2/2]

AppLog & ost::AppLog::debug ( void )
inline

debug level

Returns
application logger stream

Definition at line 454 of file applog.h.

◆ emerg() [1/2]

void ost::AppLog::emerg ( const char * format,
... )

emerg level printf style method, provided for convenience.

Parameters
formatprintf format

◆ emerg() [2/2]

AppLog & ost::AppLog::emerg ( void )
inline

emerg level

Returns
application logger stream

Definition at line 461 of file applog.h.

◆ error() [1/2]

void ost::AppLog::error ( const char * format,
... )

error level printf style method, provided for convenience.

Parameters
formatprintf format

◆ error() [2/2]

AppLog & ost::AppLog::error ( void )
inline

error level

Returns
application logger stream

Definition at line 447 of file applog.h.

◆ identLevel()

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

Sets the level for that ident.

Parameters
identident (module name for instance).
levellevel

◆ info() [1/2]

void ost::AppLog::info ( const char * format,
... )

info level printf style method, provided for convenience.

Parameters
formatprintf format

◆ info() [2/2]

AppLog & ost::AppLog::info ( void )
inline

info level

Returns
application logger stream

Definition at line 489 of file applog.h.

◆ level()

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

Sets the log level.

Parameters
enablelog level.

◆ levelTranslate()

static Slog::Level ost::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 507 of file applog.h.

◆ logFileName()

void ost::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

◆ notice() [1/2]

void ost::AppLog::notice ( const char * format,
... )

notice level printf style method, provided for convenience.

Parameters
formatprintf format

◆ notice() [2/2]

AppLog & ost::AppLog::notice ( void )
inline

notice level

Returns
application logger stream

Definition at line 482 of file applog.h.

◆ open()

void ost::AppLog::open ( const char * ident)

Opens the file if not already and sets ident.

Parameters
identmodule name for instance.

◆ operator()() [1/3]

AppLog & ost::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

◆ operator()() [2/3]

AppLog & ost::AppLog::operator() ( const Ident & ident)
inline

operator to change ident

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

Definition at line 393 of file applog.h.

Here is the call graph for this function:

◆ operator()() [3/3]

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

operator to change logging level

Parameters
levelnew log level
Returns
application logger stream

◆ operator<<() [1/3]

AppLog & ost::AppLog::operator<< ( AppLog &(* pfManipulator )(AppLog &))

manipulator operator, to change print levels.

Parameters
(*pfManipulator)(AppLog &)
Returns
application logger stream

◆ operator<<() [2/3]

AppLog & ost::AppLog::operator<< ( Ident & ident)
inline

operator <<

Parameters
identmodule name for instance.
Returns
application logger stream

Definition at line 429 of file applog.h.

Here is the call graph for this function:

◆ operator<<() [3/3]

AppLog & ost::AppLog::operator<< ( ostream &(* pfManipulator )(ostream &))

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

std::endl,...)

Parameters
(*pfManipulator)(AppLog &)
Returns
application logger stream

◆ overflow()

virtual int ost::AppLog::overflow ( int c)
virtual

stream overflow() overload.

Parameters
ccharacter to be managed
Returns
c

◆ slogEnable()

void ost::AppLog::slogEnable ( bool en = true)

Enables slog output for error level messages.

Parameters
entrue to enable slog output.

◆ warn() [1/2]

void ost::AppLog::warn ( const char * format,
... )

warn level printf style method, provided for convenience.

Parameters
formatprintf format

◆ warn() [2/2]

AppLog & ost::AppLog::warn ( void )
inline

warn level

Returns
application logger stream

Definition at line 440 of file applog.h.

Friends And Related Symbol Documentation

◆ operator<<

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

Definition at line 419 of file applog.h.

Field Documentation

◆ assoc

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

Definition at line 179 of file applog.h.

◆ d

AppLogPrivate* ost::AppLog::d
protected

Definition at line 177 of file applog.h.


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