OFLogFile Class Reference

Class that provides a general purpose facility for writing log files. More...

List of all members.

Public Types

enum  LF_Level {
  LL_none = 0, LL_error = 1, LL_warning = 2, LL_informational = 3,
  LL_debug = 4
}
 describes the different status levels used for the log file messages More...

Public Member Functions

 OFLogFile (const char *filename, int flags=ios::app)
 constructor, creates a log file of the specified name.
virtual ~OFLogFile ()
 destructor
ofstream & lockFile (LF_Level level=LL_none, const char *module=NULL)
 acquires a lock on the log file stream and returns a reference to the stream.
void unlockFile ()
 releases the lock on the log file stream.
OFBool good ()
 checks whether log file could be created.
ostream & getFile ()
 returns a reference to the current log file stream.
void writeMessage (const char *message, int indent=3)
 writes a message to the log file stream.
void setFilter (LF_Level level)
 sets a filter to specify which messages are actually written to the log file.
LF_Level getFilter ()
 gets the currently active filter.
OFBool checkFilter (LF_Level level)
 checks whether the current filter allows out of messages of the given status level.

Private Member Functions

 OFLogFile (const OFLogFile &arg)
 private undefined copy constructor
OFLogFileoperator= (const OFLogFile &arg)
 private undefined assignment operator

Private Attributes

ofstream File
 log file stream
LF_Level Filter
 log message filter


Detailed Description

Class that provides a general purpose facility for writing log files.

Protection for simultaneous access from different threads is implemented if the module is compiled with -D_REENTRANT.

Definition at line 49 of file oflogfil.h.


Member Enumeration Documentation

enum OFLogFile::LF_Level
 

describes the different status levels used for the log file messages

Enumerator:
LL_none  no log messages (only used as a filter)
LL_error  only error messages
LL_warning  warning messages (includes LL_error)
LL_informational  informational messages (includes LL_warning)
LL_debug  debug messages (includes LL_informational)

Definition at line 55 of file oflogfil.h.


Constructor & Destructor Documentation

OFLogFile::OFLogFile const char *  filename,
int  flags = ios::app
 

constructor, creates a log file of the specified name.

Use method good() to check whether the output file could be created.

Parameters:
filename name of the log file to be created
flags file type used to create the file (default: append)

Referenced by checkFilter().


Member Function Documentation

OFBool OFLogFile::checkFilter LF_Level  level  )  [inline]
 

checks whether the current filter allows out of messages of the given status level.

Parameters:
level status level to be checked
Returns:
OFTrue if message should be written, OFFalse otherwise

Definition at line 165 of file oflogfil.h.

References Filter, LL_none, OFLogFile(), and operator=().

ostream& OFLogFile::getFile  )  [inline]
 

returns a reference to the current log file stream.

This method neither locks nor unlocks the stream - the called must ensure that the stream is locked and unlocked appropriately.

Returns:
reference to log file stream

Definition at line 120 of file oflogfil.h.

References File.

LF_Level OFLogFile::getFilter  )  [inline]
 

gets the currently active filter.

Returns:
status level specifying the filter

Definition at line 156 of file oflogfil.h.

References Filter.

OFBool OFLogFile::good  )  [inline]
 

checks whether log file could be created.

Returns:
OFTrue if file status is OK, OFFalse otherwise

Definition at line 103 of file oflogfil.h.

References File.

ofstream& OFLogFile::lockFile LF_Level  level = LL_none,
const char *  module = NULL
 

acquires a lock on the log file stream and returns a reference to the stream.

An optional header (incl. date, time, status level and module name) is automatically written to the stream if level is not LL_none.

Parameters:
level status level of the following message (optional)
module name of the module the message belongs to (optional)
Returns:
reference to log file stream (used to write the message)

void OFLogFile::setFilter LF_Level  level  )  [inline]
 

sets a filter to specify which messages are actually written to the log file.

There are five different levels (in ascending order): none, informational, warning, error, debug. All messages which belong to a 'lower' level are included in the higher levels, i.e. the level debug includes all messages. Since this method uses the class mutex the filter cannot be changed while the file access is locked.

Parameters:
level status level specifying the filter

Definition at line 142 of file oflogfil.h.

References Filter.

void OFLogFile::writeMessage const char *  message,
int  indent = 3
 

writes a message to the log file stream.

Each line has an indentation of the specified number of spaces. This method neither locks nor unlocks the stream - the called must ensure that the stream is locked and unlocked appropriately.

Parameters:
message text to be written to the stream (newline with '
')
indent number of spaces each line is started with (optional)


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


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5