ionflux.org | Impressum

Ionflux::Tools::Reporter Class Reference
[Output/Logging facilities]

Reporter. More...

#include <Reporter.hpp>

Collaboration diagram for Ionflux::Tools::Reporter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Reporter ()
 Constructor.
 Reporter (int initVerbosityLevel, int initLogLevel, const std::string &initLogPath, const std::string &initLogPrefix, const std::string &initLogSuffix, bool initConsoleTimestamp[], bool initLogTimestamp[])
 Constructor.
virtual ~Reporter ()
 Destructor.
virtual void setConfig (Node &config)
 Set configuration.
virtual void setVerbosityLevel (int level)
 Set verbosity level.
virtual int getVerbosityLevel ()
 Get verbosity level.
virtual void setLogLevel (int level)
 Set log level.
virtual int getLogLevel ()
 Get log level.
virtual void setLogFilePath (const std::string &path)
 Set log file path.
virtual std::string getLogFilePath ()
 Get log file path.
virtual void setLogFilePrefix (const std::string &prefix)
 Set log file prefix.
virtual std::string getLogFilePrefix ()
 Get log file prefix.
virtual void setLogFileSuffix (const std::string &suffix)
 Set log file suffix.
virtual std::string getLogFileSuffix ()
 Get log file prefix.
virtual void setTimestamps (bool console[], bool log[])
 Set timestamp options.
virtual void msg (const std::string &message, int level)
 Submit message for output/logging.
virtual void msg (const std::string &message, int level, bool lineTerm)
 Submit message for output/logging.
virtual void msg (const std::string &message, int level, bool lineTerm, bool timeStamp)
 Submit message for output/logging.
virtual bool assert (bool assertExpr, const std::string &message)
 Assertion.
virtual void writeLogMessage (const std::string &fileName, const std::string &message)
 Write a message to a logfile.
virtual int getLevel (const std::string &level)
 Get numerical verbosity level.
virtual void setAddLineTerm (bool status)
 Set line terminator option.
virtual void redirect (Reporter *newTarget)
 Set redirection target.
virtual void setDump (ByteDump *newDump)
 Set byte dump.
virtual void setCompressLogs (bool newCompressLogs)
 Set logfile compression flag.
virtual bool getCompressLogs ()
 Get logfile compression flag.

Static Public Member Functions

static std::string createTimestamp (bool useDate, bool useTime, const std::string &dateSep, const std::string &dateTimeSep, const std::string &timeSep, DateTime &dt)
 Create a timestamp.

Static Public Attributes

static const std::string DEFAULT_LOGFILE_SUFFIX = ".log"
 Default log file suffix.
static const std::string DEFAULT_LOG_PATH = "logs"
 Default log path.
static const int VL_ASSERT = -20
 Verbosity/Log level: Assertion.
static const int VL_NONE = 0
 Verbosity/Log level: Don't output any messages at all.
static const int VL_ERROR_CRIT = 20
 Verbosity/Log level: Output critical errors only.
static const int VL_ERROR = 40
 Verbosity/Log level: Include (normal) errors.
static const int VL_WARNING = 60
 Verbosity/Log level: Include warnings.
static const int VL_WARNING_OPT = 80
 Verbosity/Log level: Include optional warnings (pedantic mode ;-)).
static const int VL_INFO = 100
 Verbosity/Log level: Include informational messages.
static const int VL_INFO_OPT = 120
 Verbosity/Log level: Include optional informational messages.
static const int VL_DEBUG = 140
 Verbosity/Log level: Include debug messages.
static const int VL_DEBUG_OPT = 160
 Verbosity/Log level: Include optional debug messages.
static const int VL_DEBUG_INSANE = 180
 Verbosity/Log level: Include insanely detailed debug messages.
static const int VL_ALL = 500
 Verbosity/Log level: Output all messages.

Protected Attributes

int verbosityLevel
 The current verbosity level.
int logLevel
 The current log level.
std::string logFilePath
 The path where log files should be stored.
std::string logFilePrefix
 The log file prefix.
std::string logFileSuffix
 The log file suffix.
bool consoleTimestamp [2]
 Which timestamps should be used for console output.
bool logTimestamp [2]
 Which timestamps should be used for console output.
bool addLineTerm
 Whether missing line terminators should be added.
bool disableTimestamps
 Whether to disable timestamps completely.
ByteDumpdump
 Optional target to redirect console output to.
Reportertarget
 Optional Reporter to redirect output to.
bool compressLogs
 Compress logfiles flag.
DateTime lastLogTime
 Datetime of last log entry.
std::string lastLogName
 File name of last log entry.

Detailed Description

Reporter.

Allows console output and logging at configurable verbosity and log levels.

The Reporter::VL_INFO and Reporter::VL_INFO_OPT verbosity levels are special in that messages on these levels will be written to standard output (cout). Messages on all other levels will be written to standard error output (cerr).


Constructor & Destructor Documentation

Ionflux::Tools::Reporter::Reporter  ) 
 

Constructor.

Construct new Reporter object.

Ionflux::Tools::Reporter::Reporter int  initVerbosityLevel,
int  initLogLevel,
const std::string &  initLogPath,
const std::string &  initLogPrefix,
const std::string &  initLogSuffix,
bool  initConsoleTimestamp[],
bool  initLogTimestamp[]
 

Constructor.

Construct new Reporter object.

Parameters:
initVerbosityLevel Verbosity level.
initLogLevel Log level.
initLogPath Path where log files should be stored.
initLogPrefix Prefix for log file names.
initLogSuffix Suffix for log file names.
initConsoleTimestamp Timestamp options for console output.
initLogTimestamp Timestamp options for log file output.

Ionflux::Tools::Reporter::~Reporter  )  [virtual]
 

Destructor.

Destruct Reporter object.


Member Function Documentation

bool Ionflux::Tools::Reporter::assert bool  assertExpr,
const std::string &  message
[virtual]
 

Assertion.

Perform an assertion check. If the check fails (i.e., assertExpr evaluates to false), the message is passed to the output facility, otherwise no action is taken.

Parameters:
assertExpr Assertion to be evaluated.
message Message associated with a failed assertion.
Returns:
Value of the assertion expression assertExpr.

std::string Ionflux::Tools::Reporter::createTimestamp bool  useDate,
bool  useTime,
const std::string &  dateSep,
const std::string &  dateTimeSep,
const std::string &  timeSep,
DateTime dt
[static]
 

Create a timestamp.

Creates a timestamp using the specified options.

Parameters:
useDate Include current date in timestamp.
useTime Include current time in timestamp.
dateSep Separator for date elements.
dateTimeSep Separator between date and time.
timeSep Separator for time elements.
dt Datetime to be used for the time stamp.
Returns:
Timestamp.

bool Ionflux::Tools::Reporter::getCompressLogs  )  [virtual]
 

Get logfile compression flag.

Returns:
true if logfile compression is enabled, false otherwise.

int Ionflux::Tools::Reporter::getLevel const std::string &  level  )  [virtual]
 

Get numerical verbosity level.

Translates a verbosity or log level identified by a string to its numerical counterpart which is used by Reporter functions.

Parameters:
level The string representation of the verbosity/log level.
Returns:
Verbosity/log level.

std::string Ionflux::Tools::Reporter::getLogFilePath  )  [virtual]
 

Get log file path.

Get the current log file path.

Returns:
Current log file path.

std::string Ionflux::Tools::Reporter::getLogFilePrefix  )  [virtual]
 

Get log file prefix.

Get the current log file prefix.

Returns:
Current log file prefix.

std::string Ionflux::Tools::Reporter::getLogFileSuffix  )  [virtual]
 

Get log file prefix.

Get the current log file suffix.

Returns:
Current log file suffix.

int Ionflux::Tools::Reporter::getLogLevel  )  [virtual]
 

Get log level.

Get the current log level.

Note:
If the reporter object is redirected, this will return the current log level of the target.
Returns:
Current log level.

int Ionflux::Tools::Reporter::getVerbosityLevel  )  [virtual]
 

Get verbosity level.

Get the current verbosity level.

Note:
If the reporter object is redirected, this will return the current verbosity level of the target.
Returns:
Current verbosity level.

void Ionflux::Tools::Reporter::msg const std::string &  message,
int  level,
bool  lineTerm,
bool  timeStamp
[virtual]
 

Submit message for output/logging.

Use this function to submit a message for console output or logging. The Reporter class will then do all the rest. :-)
This function allows you to override the default line termination setting and the default timestamp settings.

Parameters:
message The message to be written to the console or a logfile.
level The log/verbosity level of the message. Should be one of the constants defined in Reporter.
lineTerm Whether to add missing line terminators.
timeStamp Whether to disable timestamps for this message.

void Ionflux::Tools::Reporter::msg const std::string &  message,
int  level,
bool  lineTerm
[virtual]
 

Submit message for output/logging.

Use this function to submit a message for console output or logging. The Reporter class will then do all the rest. :-)
This function allows you to override the default line termination setting.

Parameters:
message The message to be written to the console or a logfile.
level The log/verbosity level of the message. Should be one of the constants defined in Reporter.
lineTerm Whether to add missing line terminators.

void Ionflux::Tools::Reporter::msg const std::string &  message,
int  level
[virtual]
 

Submit message for output/logging.

Use this function to submit a message for console output or logging. The Reporter class will then do all the rest. :-)

Parameters:
message The message to be written to the console or a logfile.
level The log/verbosity level of the message. Should be one of the constants defined in Reporter.

void Ionflux::Tools::Reporter::redirect Reporter newTarget  )  [virtual]
 

Set redirection target.

Set a target Reporter object for output redirection. This effectively bypasses all log level settings of the redirecting object.

Parameters:
newTarget Target the output should be redirected to.

void Ionflux::Tools::Reporter::setAddLineTerm bool  status  )  [virtual]
 

Set line terminator option.

Use this function to set whether line terminators should be appended to messages lacking them.
Default is to append missing line terminators ('true').

Parameters:
status Whether missing line terminators should be added.

void Ionflux::Tools::Reporter::setCompressLogs bool  newCompressLogs  )  [virtual]
 

Set logfile compression flag.

Sets the logfile compression flag. If set to true, logfiles will be compressed at the end of a day.

Parameters:
newCompressLogs Whether to compress logfiles.

void Ionflux::Tools::Reporter::setConfig Node config  )  [virtual]
 

Set configuration.

Sets the output/logging configuration from a configuration node.

Parameters:
config Configuration node.

void Ionflux::Tools::Reporter::setDump ByteDump newDump  )  [virtual]
 

Set byte dump.

Use this function to specify a byte dump. All console output will be redirected to the byte dump instead of being output to the console. You can pass null to this function disable the redirection.

Parameters:
newDump Target for output redirection.

void Ionflux::Tools::Reporter::setLogFilePath const std::string &  path  )  [virtual]
 

Set log file path.

Sets the path where log files should be stored.

Parameters:
path The new log file path.

void Ionflux::Tools::Reporter::setLogFilePrefix const std::string &  prefix  )  [virtual]
 

Set log file prefix.

Sets the prefix to be prepended to log file names. This should be something unique to the application or module you wish to create logs for. Otherwise log data for different applications might get written to the same file.

Parameters:
prefix The new log file prefix.

void Ionflux::Tools::Reporter::setLogFileSuffix const std::string &  suffix  )  [virtual]
 

Set log file suffix.

Sets the suffix to be appended to log file names.

Parameters:
suffix The new log file suffix.

void Ionflux::Tools::Reporter::setLogLevel int  level  )  [virtual]
 

Set log level.

Sets the log level for messages written to the logfile.

Parameters:
level The new log level. Should be one of the constants defined in Reporter.

void Ionflux::Tools::Reporter::setTimestamps bool  console[],
bool  log[]
[virtual]
 

Set timestamp options.

Use this function to specify which timestamps you want to have in your console output or logs. Each parameter is an array of two booleans. Set the first value to 'true' to enable date timestamps, use the second value for time timestamps. Any combination is possible, while it doesn't necessarily have to make sense. ;-)
Default is no timestamps for console output and time timestamps for logfile output.

Parameters:
console Timestamp options for console output.
log Timestamp options for logfile output.

void Ionflux::Tools::Reporter::setVerbosityLevel int  level  )  [virtual]
 

Set verbosity level.

Sets the verbosity level for console messages.

Parameters:
level The new verbosity level. Should be one of the constants defined in Reporter.

void Ionflux::Tools::Reporter::writeLogMessage const std::string &  fileName,
const std::string &  message
[virtual]
 

Write a message to a logfile.

Writes the message to specified logfile.

Parameters:
fileName File name of the logfile.
message The message to be written to the logfile.


Member Data Documentation

bool Ionflux::Tools::Reporter::addLineTerm [protected]
 

Whether missing line terminators should be added.

bool Ionflux::Tools::Reporter::compressLogs [protected]
 

Compress logfiles flag.

bool Ionflux::Tools::Reporter::consoleTimestamp[2] [protected]
 

Which timestamps should be used for console output.

const std::string Ionflux::Tools::Reporter::DEFAULT_LOG_PATH = "logs" [static]
 

Default log path.

const std::string Ionflux::Tools::Reporter::DEFAULT_LOGFILE_SUFFIX = ".log" [static]
 

Default log file suffix.

bool Ionflux::Tools::Reporter::disableTimestamps [protected]
 

Whether to disable timestamps completely.

ByteDump* Ionflux::Tools::Reporter::dump [protected]
 

Optional target to redirect console output to.

std::string Ionflux::Tools::Reporter::lastLogName [protected]
 

File name of last log entry.

DateTime Ionflux::Tools::Reporter::lastLogTime [protected]
 

Datetime of last log entry.

std::string Ionflux::Tools::Reporter::logFilePath [protected]
 

The path where log files should be stored.

std::string Ionflux::Tools::Reporter::logFilePrefix [protected]
 

The log file prefix.

std::string Ionflux::Tools::Reporter::logFileSuffix [protected]
 

The log file suffix.

int Ionflux::Tools::Reporter::logLevel [protected]
 

The current log level.

bool Ionflux::Tools::Reporter::logTimestamp[2] [protected]
 

Which timestamps should be used for console output.

Reporter* Ionflux::Tools::Reporter::target [protected]
 

Optional Reporter to redirect output to.

int Ionflux::Tools::Reporter::verbosityLevel [protected]
 

The current verbosity level.

const int Ionflux::Tools::Reporter::VL_ALL = 500 [static]
 

Verbosity/Log level: Output all messages.

const int Ionflux::Tools::Reporter::VL_ASSERT = -20 [static]
 

Verbosity/Log level: Assertion.

Assertions are output regardless of the log level settings, because they usually indicate that something is seriously wrong with the program.

const int Ionflux::Tools::Reporter::VL_DEBUG = 140 [static]
 

Verbosity/Log level: Include debug messages.

const int Ionflux::Tools::Reporter::VL_DEBUG_INSANE = 180 [static]
 

Verbosity/Log level: Include insanely detailed debug messages.

const int Ionflux::Tools::Reporter::VL_DEBUG_OPT = 160 [static]
 

Verbosity/Log level: Include optional debug messages.

const int Ionflux::Tools::Reporter::VL_ERROR = 40 [static]
 

Verbosity/Log level: Include (normal) errors.

const int Ionflux::Tools::Reporter::VL_ERROR_CRIT = 20 [static]
 

Verbosity/Log level: Output critical errors only.

const int Ionflux::Tools::Reporter::VL_INFO = 100 [static]
 

Verbosity/Log level: Include informational messages.

const int Ionflux::Tools::Reporter::VL_INFO_OPT = 120 [static]
 

Verbosity/Log level: Include optional informational messages.

const int Ionflux::Tools::Reporter::VL_NONE = 0 [static]
 

Verbosity/Log level: Don't output any messages at all.

const int Ionflux::Tools::Reporter::VL_WARNING = 60 [static]
 

Verbosity/Log level: Include warnings.

const int Ionflux::Tools::Reporter::VL_WARNING_OPT = 80 [static]
 

Verbosity/Log level: Include optional warnings (pedantic mode ;-)).


The documentation for this class was generated from the following files:
Generated on Tue Mar 14 21:09:17 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6