library of assembled shared sources

http://lass.cocamware.com

lass::io::Logger Class Reference

Logs proxy streams to files. More...

#include <logger.h>


Public Types

enum  LogMode { lmAppend, lmClear }
typedef ProxyOStream::TMask TMask

Public Member Functions

 Logger (const std::string &iLogFile, LogMode iLogMode=lmClear)
 Default constructor for the sake of static library.
 ~Logger ()
 Unsubscribe to all proxys.
void subscribeTo (ProxyOStream *iProxy, TMask iFilter=ProxyOStream::acceptAll)
 Subscribe this logger to a proxy stream and set the filter on it.
void unsubscribeTo (ProxyOStream *iProxy)
 Unsubscribe this logger to a proxy stream.
TMask filter (ProxyOStream *iProxy)
 return the filter between proxy and logger
void setFilter (ProxyOStream *iProxy, TMask iFilter)
 Set filter between proxy and logger.

Private Types

typedef std::list< ProxyOStream * > TProxyList

Private Member Functions

void openLog (const std::string &iLogFile, LogMode iLogMode=lmClear)
 open file to write logs to.

Private Attributes

std::ofstream logFile_
TProxyList proxyList_


Detailed Description

Logs proxy streams to files.

Date:
2003
Construct a logger and subscribe it to proxy streams so it can log them. All output to all proxy streams it is subscribed to will be saved to a file. Per proxy stream you can set a filter of what messages should be logged. The logger will unsubscribe itself on destruction.

  Logger logger("logfile.txt");       // construct logger\n
  logger.subscribe(proxyOut());       // subsribe to the proxy out stream.\n
  ...\n
  logger.unsubscribe(proxyOut());\n

Definition at line 80 of file logger.h.


Member Typedef Documentation

Definition at line 90 of file logger.h.

typedef std::list<ProxyOStream*> lass::io::Logger::TProxyList [private]

Definition at line 104 of file logger.h.


Member Enumeration Documentation

Enumerator:
lmAppend 
lmClear 

Definition at line 84 of file logger.h.


Constructor & Destructor Documentation

lass::io::Logger::Logger ( const std::string &  iLogFilename,
LogMode  iLogMode = lmClear 
)

Default constructor for the sake of static library.

We don't recommend of using it. Create a logger to a log file and specify if it must append to the file or clear it.

Definition at line 62 of file logger.cpp.

References openLog().

lass::io::Logger::~Logger (  ) 

Unsubscribe to all proxys.

Definition at line 71 of file logger.cpp.

References logFile_, proxyList_, and lass::io::ProxyOStream::remove().


Member Function Documentation

void lass::io::Logger::subscribeTo ( ProxyOStream iProxy,
TMask  iFilter = ProxyOStream::acceptAll 
)

Subscribe this logger to a proxy stream and set the filter on it.

Parameters:
iProxy if null pointer, then an exception is thrown.
iFilter filter between proxy and logger

Definition at line 86 of file logger.cpp.

References lass::io::ProxyOStream::add(), LASS_ENFORCE_POINTER, logFile_, and proxyList_.

void lass::io::Logger::unsubscribeTo ( ProxyOStream iProxy  ) 

Unsubscribe this logger to a proxy stream.

Parameters:
iProxy if null pointer, then an exception is thrown.

Definition at line 97 of file logger.cpp.

References LASS_ENFORCE_POINTER, logFile_, proxyList_, and lass::io::ProxyOStream::remove().

Logger::TMask lass::io::Logger::filter ( ProxyOStream iProxy  ) 

return the filter between proxy and logger

Parameters:
iProxy logger must be subscribed to this proxy (and proxy should not be a NULL pointer), otherwise and exception is thrown.

Definition at line 109 of file logger.cpp.

References LASS_ENFORCE_POINTER, and logFile_.

void lass::io::Logger::setFilter ( ProxyOStream iProxy,
TMask  iFilter 
)

Set filter between proxy and logger.

Parameters:
iProxy logger must be subscribed to this proxy (and proxy should not be a NULL pointer), otherwise and exception is thrown.
iFilter the filter between proxy and logger.

Definition at line 121 of file logger.cpp.

References LASS_ENFORCE_POINTER, and logFile_.

void lass::io::Logger::openLog ( const std::string &  iLogFilename,
LogMode  iLogMode = lmClear 
) [private]

open file to write logs to.

You should do this in (and only in) the constructor. The Logger doesn't like to have no filestreams open, or to change the file stream since it relies on it to subscribe to the different proxy streams. So make sure that you have a file stream op after construction, and that you never change it!

QUESTION: is this true? afterall, if you open a different file, the pointer to lofFile_ will not change, but maybe the proxy streams don't like closed filestreams?

Definition at line 137 of file logger.cpp.

References LASS_THROW, lmAppend, logFile_, and lass::prim::out().

Referenced by Logger().


Field Documentation

std::ofstream lass::io::Logger::logFile_ [private]

Definition at line 108 of file logger.h.

Referenced by filter(), openLog(), setFilter(), subscribeTo(), unsubscribeTo(), and ~Logger().

Definition at line 109 of file logger.h.

Referenced by subscribeTo(), unsubscribeTo(), and ~Logger().


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

Generated on Mon Nov 10 14:22:09 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo