#include <Iguana/Utilities/classlib/utils/Log.h>
Public Types | |
enum | State { Trace, Warning, Error } |
Public Member Functions | |
bool | deep (void) const |
logstream & | enable (bool value=true) |
bool | enabled (void) const |
logstream & | flush (void) |
logstream & | indent (int by=4) |
logstream (void) | |
logstream & | mode (logflag &flag, int level) |
logstream & | operator<< (std::streambuf *buffer) |
logstream & | operator<< (ios &(*fn)(ios &)) |
logstream & | operator<< (logstream &(*fn)(logstream &)) |
logstream & | operator<< (long double f) |
logstream & | operator<< (float f) |
logstream & | operator<< (double f) |
logstream & | operator<< (unsigned short n) |
logstream & | operator<< (short n) |
logstream & | operator<< (unsigned long n) |
logstream & | operator<< (long n) |
logstream & | operator<< (unsigned int n) |
logstream & | operator<< (int n) |
logstream & | operator<< (const void *pointer) |
logstream & | operator<< (const std::string &string) |
logstream & | operator<< (const signed char *string) |
logstream & | operator<< (const unsigned char *string) |
logstream & | operator<< (const char *string) |
logstream & | operator<< (signed char ch) |
logstream & | operator<< (unsigned char ch) |
logstream & | operator<< (char ch) |
logstream & | put (signed char ch) |
logstream & | put (unsigned char ch) |
logstream & | put (char ch) |
logstream & | recurse (bool recursion=true) |
logstream & | registerMode (logflag &mode) |
logstream & | select (logflag &flag) |
bool | selected (void) const |
logstream & | state (State value) |
logstream & | undent (int by=4) |
logstream & | unselect (logflag &flag) |
virtual | ~logstream (void) |
Static Public Member Functions | |
static logstream & | error (logflag &mode, int level) |
static logstream & | logger (void) |
static logstream & | trace (logflag &mode, int level) |
static logstream & | warning (logflag &mode, int level) |
Protected Member Functions | |
virtual void | emit (const char *string, int length)=0 |
Private Member Functions | |
void | pad (int n) |
void | readjust (void) |
Static Private Member Functions | |
static void | checkMode (logflag &mode) |
static logstream * | createConsoleLogDevice (const char *args) |
static logstream * | createFileLogDevice (const char *args) |
static logstream * | createLocalSocketLogDevice (const char *args) |
static logstream * | createPipeLogDevice (const char *args) |
static logstream * | createSinkLogDevice (const char *args) |
static logstream * | createSocketLogDevice (bool local, bool tcp, const char *args) |
static logstream * | createStderrLogDevice (const char *args) |
static logstream * | createTcpSocketLogDevice (const char *args) |
static logstream * | createUdpSocketLogDevice (const char *args) |
Private Attributes | |
buf * | m_buf |
The logging output buffer. | |
bool | m_deep |
A flag indicating that objects should dump their contents recursively. | |
bool | m_enabled |
A flag indicating whether logging is enabled at all. | |
int | m_indent |
The current indent level. | |
int | m_longestModeName |
The length of the longest mode name seen so far. | |
bool | m_longLineHeader |
A flag indicating whether the line header should be printed in the long format. | |
const logflag * | m_mode |
The current mode flag; defaults to LFall. | |
int | m_modeNameLength |
The length of the current mode name. | |
bool | m_newline |
Flag indicating whether the output is at the beginning of the line and the new line should prefixed and indented before actually outputting anything. | |
bool | m_selected |
A flag indicating whether stream is in selected state, i.e., the current mode has been enabled and the level is chosen. | |
State | m_state |
The current state (error, warning or trace). | |
std::ostream * | m_stream |
The real output engine. | |
Static Private Attributes | |
static bool | s_deleted |
A flag to indicate when the logging system has been destroyed. | |
static device | s_devices [] |
List of available logging devices. | |
static logflag * | s_flags |
The chain of registered log flags (i.e., used so far). | |
static bool | s_initialized |
A flag to indicate when the logging system has been initialized. | |
static logstream * | s_logger |
Pointer to the logging device used by the LOG() macros. | |
Friends | |
class | buf |
logstream selectively outputs the objects sent to it. The selection is done according to the current logging mode and level. It is also possible to enable and disabled the whole system separately from the modes. Output in a disabled mode is discarded.
There are several ways to control the logging behaviour. Firstly, the program can define default settings for the log flags and call the logstream methods. Secondly, the user can override the default settings from environment variables. Thirdly, the actual LOG() calls will selectively output the data. Finally, all the logging code can be compiled conditionally.
logstream interface is very similar to that of std::ostream
. The left shift insertion operator can be used to send objects to the log. The standard stream manipulators work as usual. Polymorphic classes might wish to to inherit from Debuggable to gain more advanced dumping facilities.
logstream only uses std::ostream
for implementation---it does not inherit from one. Most of the features not available in logstream wouldn't be meaningful anyway. In particular the user defined std::ostream
insertion operators do not work. logstream is meant for dumping objects' internal representation for debugging purposes, thus the std::ostream
inserters would seldomly do the right thing.
logstream does not require any methods or attributes from the the logged objects, and thus the interface is limited to that of std::ostream
. However, there is support for more complex operations than what are allowed by bare std::ostream
, such as:
The indentation level can be used to clarify complex data structures or program execution. To increase indentation level by one, the program sends the indent manipulator. To decrease the level by one step, the undent manipulator is sent. The logstream takes care of everything else.
The logging output can be sent to a varieyt of logging devices: standard error, file, fifo, pipe, local or internet socket etc. The actual device to use is chosen at runtime via the $LOG
environment variable. It relatively easy to add new logging devices if the existing list is not sufficient.
The logstream class has been designed with much care to guarantee the minimum amount of interference with the rest of the program. Here are the most important principles:
errno
. On certain platforms it is not possible to do this for all logging devices but in general causes no problems. In any case no logging operation leaks an exception.
Definition at line 240 of file Log.h.
lat::logstream::logstream | ( | void | ) |
virtual lat::logstream::~logstream | ( | void | ) | [virtual] |
static logstream* lat::logstream::createConsoleLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createFileLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createLocalSocketLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createPipeLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createSinkLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createSocketLogDevice | ( | bool | local, | |
bool | tcp, | |||
const char * | args | |||
) | [static, private] |
static logstream* lat::logstream::createStderrLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createTcpSocketLogDevice | ( | const char * | args | ) | [static, private] |
static logstream* lat::logstream::createUdpSocketLogDevice | ( | const char * | args | ) | [static, private] |
logstream& lat::logstream::operator<< | ( | std::streambuf * | buffer | ) |
logstream& lat::logstream::operator<< | ( | ios &(*)(ios &) | fn | ) |
logstream& lat::logstream::operator<< | ( | long double | f | ) |
logstream& lat::logstream::operator<< | ( | float | f | ) |
logstream& lat::logstream::operator<< | ( | double | f | ) |
logstream& lat::logstream::operator<< | ( | unsigned short | n | ) |
logstream& lat::logstream::operator<< | ( | short | n | ) |
logstream& lat::logstream::operator<< | ( | unsigned long | n | ) |
logstream& lat::logstream::operator<< | ( | long | n | ) |
logstream& lat::logstream::operator<< | ( | const std::string & | string | ) |
logstream& lat::logstream::operator<< | ( | const signed char * | string | ) |
logstream& lat::logstream::operator<< | ( | const unsigned char * | string | ) |
logstream& lat::logstream::operator<< | ( | const char * | string | ) |
logstream& lat::logstream::operator<< | ( | signed char | ch | ) |
logstream& lat::logstream::operator<< | ( | unsigned char | ch | ) |
logstream& lat::logstream::operator<< | ( | char | ch | ) |
logstream& lat::logstream::put | ( | signed char | ch | ) |
logstream& lat::logstream::put | ( | unsigned char | ch | ) |
logstream& lat::logstream::put | ( | char | ch | ) |
buf* lat::logstream::m_buf [private] |
bool lat::logstream::m_deep [private] |
bool lat::logstream::m_enabled [private] |
int lat::logstream::m_indent [private] |
int lat::logstream::m_longestModeName [private] |
bool lat::logstream::m_longLineHeader [private] |
A flag indicating whether the line header should be printed in the long format.
Most applications will prefer the short format; the long format is mostly useful for daemons and multiprocess applications, where it is important to know who produced a message and when.
const logflag* lat::logstream::m_mode [private] |
int lat::logstream::m_modeNameLength [private] |
bool lat::logstream::m_newline [private] |
bool lat::logstream::m_selected [private] |
State lat::logstream::m_state [private] |
std::ostream* lat::logstream::m_stream [private] |
bool lat::logstream::s_deleted [static, private] |
device lat::logstream::s_devices[] [static, private] |
logflag* lat::logstream::s_flags [static, private] |
bool lat::logstream::s_initialized [static, private] |
logstream* lat::logstream::s_logger [static, private] |