Bayonne2 / Common C++ 2 Framework
|
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>
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... | |
AppLog & | operator() (const char *ident, Slog::Level level=Slog::levelError) |
operator to change ident and log level More... | |
AppLog & | operator() (Ident &ident) |
operator to change ident More... | |
AppLog & | operator() (Slog::Level level) |
operator to change logging level More... | |
AppLog & | operator<< (AppLog &(*pfManipulator)(AppLog &)) |
manipulator operator, to change print levels. More... | |
AppLog & | operator<< (ostream &(*pfManipulator)(ostream &)) |
manipulator operator, to use ostream manipulators (i.e. More... | |
AppLog & | operator<< (Ident &ident) |
operator << More... | |
AppLog & | warn (void) |
warn level More... | |
AppLog & | error (void) |
error level More... | |
AppLog & | debug (void) |
debug level More... | |
AppLog & | emerg (void) |
emerg level More... | |
AppLog & | alert (void) |
alert level More... | |
AppLog & | critical (void) |
critical level More... | |
AppLog & | notice (void) |
notice level More... | |
AppLog & | info (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) |
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;
AppLog::AppLog | ( | const char * | logFileName = NULL , |
bool | logDirectly = false , |
||
bool | usePipe = false |
||
) |
Constructor for a customized logger.
logFileName | log file name. |
logDirectly | true to write directly to file, false to use a spooler like logger. |
usePipe | true to use pipe instead of file, false otherwise |
|
virtual |
Destructor.
|
inline |
void AppLog::clogEnable | ( | bool | en = true | ) |
Enables clog output.
en | true to enable clog output. |
void AppLog::close | ( | void | ) |
if logDirectly is set it closes the file.
|
inline |
|
inline |
|
inline |
|
inline |
void AppLog::identLevel | ( | const char * | ident, |
Slog::Level | level | ||
) |
Sets the level for that ident.
ident | ident (module name for instance). |
level | level |
|
inline |
void AppLog::level | ( | Slog::Level | enable | ) |
Sets the log level.
enable | log level. |
|
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
name | Slog Level name |
void AppLog::logFileName | ( | const char * | FileName, |
bool | logDirectly = false , |
||
bool | usePipe = false |
||
) |
Allows to set up ost::alog parameters.
FileName | log file name. |
logDirectly | true to write directly to file, false to use a spooler like logger. |
usePipe | true to use pipe instead of file, false otherwise |
|
inline |
void AppLog::open | ( | const char * | ident | ) |
Opens the file if not already and sets ident.
ident | module name for instance. |
AppLog& AppLog::operator() | ( | const char * | ident, |
Slog::Level | level = Slog::levelError |
||
) |
operator to change ident and log level
ident | ident (module name for instance) |
level | new log level |
AppLog& AppLog::operator() | ( | Slog::Level | level | ) |
operator to change logging level
level | new log level |
manipulator operator, to change print levels.
(* | pfManipulator)(AppLog &) |
AppLog& AppLog::operator<< | ( | ostream &(*)(ostream &) | pfManipulator | ) |
manipulator operator, to use ostream manipulators (i.e.
std::endl,...)
(* | pfManipulator)(AppLog &) |
|
virtual |
void AppLog::slogEnable | ( | bool | en = true | ) |
Enables slog output for error level messages.
en | true to enable slog output. |
void AppLog::subscribe | ( | ) |
Subscribes the current thread to logger, it reserves thread safe buffer for it.
|
virtual |
stream sync() overload
void AppLog::unsubscribe | ( | ) |
Unsubscribes the current thread from logger.
|
inline |
|
protected |
|
staticprotected |