FileLogger Class Reference

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

#include <FileLogger.h++>

Inheritance diagram for FileLogger:

Inheritance graph
[legend]
Collaboration diagram for FileLogger:

Collaboration graph
[legend]

List of all members.

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.
virtual ~FileLogger ()
 Destructor.
virtual bool setFile (const String &dir, const String &name)
 Set the logging directory and log file name.
void setMaxLogSize (size_t maxLogSize)
 Set the maximum size for log files.
void setRotateCount (uint_t rotateCount)
 Set the rotation log file count.
void setFormat (const String &format)
 Set the log message format.
void log (LogLevel level, const char *file, int line, const char *message,...)
 Log a message.
void vlog (LogLevel level, const char *file, int line, const char *message, va_list args)
 Log a message.
void enableLogLevel (LogLevel level)
 Enable a specific log level.
void disableLogLevel (LogLevel level)
 Disable a specific log level.
bool isLogLevelEnabled (LogLevel level) const
 Test if a specific log level is enabled.
LogFormatgetLogFormat ()
 Get the LogFormat used by this Logger.

Static Public Attributes

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

Protected Member Functions

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

Protected Attributes

int64_t _maxFileSize
size_t _maxLogSize
size_t _curLogSize
uint_t _rotateCount
File_file
String _dir
String _name


Detailed Description

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

Author:
Mark Lindner

Constructor & Destructor Documentation

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:
format The log message format.
maxLogSize The maximum log file size, in kilobytes.
rotateCount The maximum number of backlog files to create. The value must range from 0 to 9, with 0 indicating that log rotation is disabled.

~FileLogger (  )  [virtual]

Destructor.


Member Function Documentation

bool _rotate (  )  [protected]

void disableLogLevel ( LogLevel  level  )  [inherited]

Disable a specific log level.

Parameters:
level The level to disable.

void enableLogLevel ( LogLevel  level  )  [inherited]

Enable a specific log level.

Parameters:
level The level to enable.

LogFormat& getLogFormat (  )  [inline, inherited]

Get the LogFormat used by this Logger.

bool isLogLevelEnabled ( LogLevel  level  )  const [inherited]

Test if a specific log level is enabled.

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

Log a message.

Parameters:
level The log level (severity).
file The source filename.
line The source file line number.
message The log message.
... Optional message arguments.

void openFile (  )  throw (IOException) [protected, virtual]

Open the log file.

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

Set the logging directory and log file name.

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

void setFormat ( const String format  )  [inherited]

Set the log message format.

Parameters:
format The log message format.

void setMaxLogSize ( size_t  maxLogSize  ) 

Set the maximum size for log files.

Parameters:
maxLogSize The maximum log file size, in kilobytes.

void setRotateCount ( uint_t  rotateCount  ) 

Set the rotation log file count.

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

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

Log a message.

Parameters:
level The log level (severity).
file The source filename.
line The source file line number.
message The log message.
args Optional message arguments.

bool write ( CharBuffer buffer  )  [protected, virtual]

Write a preformatted log message to the file.

Implements Logger.


Member Data Documentation

size_t _curLogSize [protected]

String _dir [protected]

File* _file [protected]

int64_t _maxFileSize [protected]

size_t _maxLogSize [protected]

String _name [protected]

uint_t _rotateCount [protected]

const size_t LOG_BUFFER_SIZE = 1024 [static, inherited]

The log buffer size.

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

const uint_t MAX_ROTATE_COUNT = 9 [static]

The maximum file rotate count.


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

Generated on Sat Apr 17 23:03:08 2010 for libcommonc++ by  doxygen 1.5.9