claw::log_system Class Reference

A class implementing a logging system. More...

#include <logger.hpp>

List of all members.

Public Types

typedef log_stream stream_type
typedef std::list< stream_type * > stream_list_type

Public Member Functions

CLAW_LOGGER_EXPORT log_system ()
 Default constructor.
CLAW_LOGGER_EXPORT ~log_system ()
 Destructor.
CLAW_LOGGER_EXPORT void clear ()
 Delete the streams.
CLAW_LOGGER_EXPORT void merge (stream_type *s)
 Add an other output stream.
CLAW_LOGGER_EXPORT void remove (const stream_type *s)
 Remove a stream.
CLAW_LOGGER_EXPORT void set (stream_type *s)
 Set the output stream.
CLAW_LOGGER_EXPORT void set_level (int lvl)
 Change the level of log.
CLAW_LOGGER_EXPORT void set_level (const log_level &lvl)
 Change the level of log.
CLAW_LOGGER_EXPORT void flush ()
 Flush all log streams.
template<typename T >
log_systemoperator<< (const T &that)
 Log something.
CLAW_LOGGER_EXPORT log_systemoperator<< (const log_level &that)
 Change the level of the next mesasges.
CLAW_LOGGER_EXPORT log_systemoperator<< (log_system &(*pf)(log_system &))
 Apply a stream modifier function to the log_system.

Private Attributes

int m_log_level
 The level of log. Messages are ignored if their level is greater than this level.
int m_message_level
 The current message level, for operator <<.
stream_list_type m_stream
 The streams in which we write de log informations.

Detailed Description

A class implementing a logging system.

Messages are sent to the log system. If the importance (level) of a message is lower or equal to a given threshold, the message is printed. Otherwise, it is ignored.

Message printing is managed by log_stream classes. The logger_system can contain several log_stream. None checking is done when adding a log_stream to see if it is already in the system.

Author:
Julien Jorge

Definition at line 67 of file logger.hpp.


Member Typedef Documentation

Definition at line 71 of file logger.hpp.

Definition at line 70 of file logger.hpp.


Constructor & Destructor Documentation

claw::log_system::log_system (  ) 

Default constructor.

The logger is initialized with a console logger.

Definition at line 45 of file logger.cpp.

00046   : m_log_level(-1), m_message_level(0)
00047 {
00048 
00049 } // log_system::~log_system()

claw::log_system::~log_system (  ) 

Destructor.

Definition at line 55 of file logger.cpp.

References clear().

00056 {
00057   clear();
00058 } // log_system::~log_system()


Member Function Documentation

void claw::log_system::clear (  ) 

Delete the streams.

Definition at line 64 of file logger.cpp.

References m_stream.

Referenced by set(), claw::application::~application(), and ~log_system().

00065 {
00066   stream_list_type::iterator it;
00067 
00068   for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
00069     delete *it;
00070 
00071   m_stream.clear();
00072 } // log_system::clear()

void claw::log_system::flush (  ) 

Flush all log streams.

Definition at line 134 of file logger.cpp.

References m_log_level, m_message_level, and m_stream.

00135 {
00136   if (m_message_level <= m_log_level)
00137     {
00138       stream_list_type::iterator it;
00139       
00140       for ( it=m_stream.begin(); it!=m_stream.end(); ++it )
00141   (*it)->flush();
00142     }
00143 } // log_system::flush()

void claw::log_system::merge ( stream_type s  ) 

Add an other output stream.

Parameters:
s Dynamicaly allocated logger_stream.

Definition at line 79 of file logger.cpp.

References m_stream.

00080 {
00081   m_stream.push_front(s);
00082 } // log_system::merge()

claw::log_system & claw::log_system::operator<< ( log_system &(*)(log_system &)  pf  ) 

Apply a stream modifier function to the log_system.

Parameters:
pf The function to apply.

Definition at line 166 of file logger.cpp.

00167 {
00168   return pf(*this);
00169 } // log_system::operator<<() [log_system& (*pf)(log_system&)]

claw::log_system & claw::log_system::operator<< ( const log_level that  ) 

Change the level of the next mesasges.

Parameters:
that The new level.

Definition at line 150 of file logger.cpp.

References claw::log_level::get(), claw::log_level::get_string(), m_log_level, and m_message_level.

00151 {
00152   m_message_level = that.get();
00153   
00154   if (m_message_level <= m_log_level)
00155     *this << that.get_string();
00156   
00157   return *this;
00158 } // log_system::operator<<() [log_level]

template<class T >
claw::log_system::log_system & claw::log_system::operator<< ( const T &  t  )  [inline]

Log something.

Parameters:
t The thing to log...
Remarks:
T must support operator<<(std::ostream&, const T&);

Definition at line 39 of file logger.tpp.

References m_log_level, m_message_level, and m_stream.

00040 {
00041   if (m_message_level <= m_log_level)
00042     {
00043       std::ostringstream oss;
00044       oss << t;
00045 
00046       typename stream_list_type::iterator it;
00047 
00048       for (it = m_stream.begin(); it!=m_stream.end(); ++it)
00049   (*it)->write(oss.str());
00050     }
00051 
00052   return *this;
00053 } // log_system::operator<<()

void claw::log_system::remove ( const stream_type s  ) 

Remove a stream.

Parameters:
s The stream to remove.
Remarks:
The search is done on the address of the pointer s.

Definition at line 90 of file logger.cpp.

References m_stream.

00091 {
00092   stream_list_type::iterator it =
00093     std::find(m_stream.begin(), m_stream.end(), s);
00094 
00095   if ( it!=m_stream.end() )
00096     m_stream.erase(it);
00097 } // log_system::remove()

void claw::log_system::set ( stream_type s  ) 

Set the output stream.

Parameters:
s Dynamicaly allocated logger_stream.

Definition at line 104 of file logger.cpp.

References clear(), and m_stream.

Referenced by claw::application::application().

00105 {
00106   clear();
00107   m_stream.push_front(s);
00108 } // log_system::set()

void claw::log_system::set_level ( const log_level lvl  ) 

Change the level of log.

Parameters:
lvl New level.

Definition at line 125 of file logger.cpp.

References claw::log_level::get(), and m_log_level.

00126 {
00127   m_log_level = lvl.get();
00128 } // log_system::set_level()

void claw::log_system::set_level ( int  lvl  ) 

Change the level of log.

Parameters:
lvl New level.

Definition at line 115 of file logger.cpp.

References m_log_level.

Referenced by claw::application::application().

00116 {
00117   m_log_level = lvl;
00118 } // log_system::set_level()


Member Data Documentation

The level of log. Messages are ignored if their level is greater than this level.

Definition at line 95 of file logger.hpp.

Referenced by flush(), operator<<(), and set_level().

The current message level, for operator <<.

Definition at line 98 of file logger.hpp.

Referenced by flush(), and operator<<().

The streams in which we write de log informations.

Definition at line 101 of file logger.hpp.

Referenced by clear(), flush(), merge(), operator<<(), remove(), and set().


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1