libcommonc++  0.7
FileLogger Class Reference

A logger that writes to a file, and can optionally perform log rotation. More...

#include <FileLogger.h++>

Inheritance diagram for FileLogger:
Collaboration diagram for FileLogger:

Public Member Functions

 FileLogger (const String &format="[%d %t] %m", size_t maxLogSize=2048, uint_t rotateCount=1)
 Construct a new FileLogger with the given log message format and logging characteristics. More...
 
virtual ~FileLogger ()
 Destructor. More...
 
virtual bool setFile (const String &dir, const String &name)
 Set the logging directory and log file name. More...
 
void setMaxLogSize (size_t maxLogSize)
 Set the maximum size for log files. More...
 
void setRotateCount (uint_t rotateCount)
 Set the rotation log file count. More...
 
void setFormat (const String &format)
 Set the log message format. More...
 
void log (LogLevel level, const char *file, int line, const char *message,...)
 Log a message. More...
 
void vlog (LogLevel level, const char *file, int line, const char *message, va_list args)
 Log a message. More...
 
void enableLogLevel (LogLevel level)
 Enable a specific log level. More...
 
void disableLogLevel (LogLevel level)
 Disable a specific log level. More...
 
bool isLogLevelEnabled (LogLevel level) const
 Test if a specific log level is enabled. More...
 
LogFormatgetLogFormat ()
 Get the LogFormat used by this Logger. More...
 

Static Public Attributes

static const uint_t MAX_ROTATE_COUNT = 9
 The maximum file rotate count. More...
 
static const size_t LOG_BUFFER_SIZE = 1024
 The log buffer size. More...
 

Protected Member Functions

virtual void openFile ()
 Open the log file. More...
 
virtual bool write (CharBuffer &buffer)
 Write a preformatted log message to the file. More...
 

Detailed Description

A logger that writes to a file, and can optionally perform log rotation.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ FileLogger()

FileLogger ( const String format = "[%d %t] %m",
size_t  maxLogSize = 2048,
uint_t  rotateCount = 1 
)

Construct a new FileLogger with the given log message format and logging characteristics.

Parameters
formatThe log message format.
maxLogSizeThe maximum log file size, in kilobytes.
rotateCountThe maximum number of backlog files to create. The value must range from 0 to 9, with 0 indicating that log rotation is disabled.

◆ ~FileLogger()

~FileLogger ( )
virtual

Destructor.

Member Function Documentation

◆ disableLogLevel()

void disableLogLevel ( LogLevel  level)
inherited

Disable a specific log level.

Parameters
levelThe level to disable.

◆ enableLogLevel()

void enableLogLevel ( LogLevel  level)
inherited

Enable a specific log level.

Parameters
levelThe level to enable.

◆ getLogFormat()

LogFormat& getLogFormat ( )
inlineinherited

Get the LogFormat used by this Logger.

◆ isLogLevelEnabled()

bool isLogLevelEnabled ( LogLevel  level) const
inherited

Test if a specific log level is enabled.

◆ log()

void log ( LogLevel  level,
const char *  file,
int  line,
const char *  message,
  ... 
)
inherited

Log a message.

Parameters
levelThe log level (severity).
fileThe source filename.
lineThe source file line number.
messageThe log message.
...Optional message arguments.

◆ openFile()

void openFile ( )
protectedvirtual

Open the log file.

Exceptions
IOExceptionIf an I/O error occurs.

◆ setFile()

bool setFile ( const String dir,
const String name 
)
virtual

Set the logging directory and log file name.

Parameters
dirThe directory in which log files will be created.
nameThe base name for the log file; log files will be named name.log, name.1.log, etc..

◆ setFormat()

void setFormat ( const String format)
inherited

Set the log message format.

Parameters
formatThe log message format.

◆ setMaxLogSize()

void setMaxLogSize ( size_t  maxLogSize)

Set the maximum size for log files.

Parameters
maxLogSizeThe maximum log file size, in kilobytes.

◆ setRotateCount()

void setRotateCount ( uint_t  rotateCount)

Set the rotation log file count.

Parameters
rotateCountThe maximum number of backlog files to create. The value must range from 0 to 9, with 0 indicating that log rotation is disabled.

◆ vlog()

void vlog ( LogLevel  level,
const char *  file,
int  line,
const char *  message,
va_list  args 
)
inherited

Log a message.

Parameters
levelThe log level (severity).
fileThe source filename.
lineThe source file line number.
messageThe log message.
argsOptional message arguments.

◆ write()

bool write ( CharBuffer buffer)
protectedvirtual

Write a preformatted log message to the file.

Implements Logger.

Member Data Documentation

◆ LOG_BUFFER_SIZE

const size_t LOG_BUFFER_SIZE = 1024
staticinherited

The log buffer size.

Indicates the maximum length of a log message, in characters. Messages which exceed this length will be truncated.

◆ MAX_ROTATE_COUNT

const uint_t MAX_ROTATE_COUNT = 9
static

The maximum file rotate count.


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