ConfigureLOGstream Class Reference

#include <logstream.hpp>

List of all members.


Detailed Description

class ConfigureLOGstream Configure and write to a log stream; type-safe, thread-safe and very portable.

Inspired by Petru Marginean, "Logging in C++," Dr.Dobbs, October 2007.

How to use: 1. include logstream.hpp in all modules that will write to the log, and (optional) define the stream. If stream is not defined, std::cout is used.

       #include "logstream.hpp"
       #include <fstream>
       //...
       std::ofstream oflog("test.log",std::ios_base::out);
       ConfigureLOG::Stream() = &oflog; // else use &(std::cout) - the default

How to use: 2. set switches to output time tags and level (default = false)

       ConfigureLOG::ReportLevels() = true;
       ConfigureLOG::ReportTimeTags() = true;

How to use: 3. set the maximum level to output. Choices (in enum LogLevel) are: ERROR,WARNING,INFO,VERBOSE,DEBUG,DEBUG1,DEBUG2,DEBUG3,DEBUG4,DEBUG5,DEBUG6,DEBUG7

       ConfigureLOG::ReportingLevel() = ConfigureLOG::Level("DEBUG");
       // (default is INFO, so ERROR, WARNING, and INFO are reported)

NB. All the ConfigureLOG:: settings are defined in ALL linked modules that includes logstream.hpp, whenever they are set in ANY such module.

How to use: 4. write to LOG(level) where level is one of the LogLevel choices. Only output at or below the ReportingLevel() will appear in log.

       LOG(INFO) << "In main(), level is " << ConfigureLOG::ReportingLevel();
       LOG(INFO) << "This is an INFO message in main";
       LOG(WARNING) << "This is a WARNING message in main";
       LOG(ERROR) << "This is an ERROR message in main";
       // the output looks like this (time is UT):
       //19:48:02.691 INFO: In main(), level is 4
       //19:48:02.691 INFO: This is an INFO message in main
       //19:48:02.691 WARNING: This is a WARNING message in main
       //19:48:02.691 ERROR: This is an ERROR message in main

How to use: 5. Change ReportingLevel() or the output Stream() at any time.

       std::ofstream ofs("test.new.log",std::ios_base::out);
       ConfigureLOG::Stream() = &ofs;       // change the log stream
       ConfigureLOG::ReportingLevel() = ConfigureLOG::Level("DEBUG7");
                                            // optionally, also change the max level
       LOG(VERBOSE) << "This is a second, special log file");
       LOG(DEBUG6) << " ... messages ...";
       //...
       ofs.close();                         // optional - not necessary for LOG
       ConfigureLOG::Stream() = &oflog;     // change back to the original log
       ConfigureLOG::ReportingLevel() = ConfigureLOG::Level("VERBOSE");
                                            // optionally, also change the max level
       // ...

Definition at line 235 of file logstream.hpp.

Static Public Member Functions

std::ostream *& Stream ()
 direct log stream output to an already opened stream, for example:
          std::ofstream oflog("mylog.log",std::ios_base::out);
          ConfigureLOGstream::Stream() = oflog;

void Output (const std::string &msg)
 used internally


Member Function Documentation

void Output const std::string &  msg  )  [inline, static]
 

used internally

Definition at line 255 of file logstream.hpp.

References Stream().

std::ostream *& Stream  )  [inline, static]
 

direct log stream output to an already opened stream, for example:

          std::ofstream oflog("mylog.log",std::ios_base::out);
          ConfigureLOGstream::Stream() = oflog;

Definition at line 249 of file logstream.hpp.

Referenced by Output(), and ConfigureLOG::Stream().


The documentation for this class was generated from the following file:
Generated on Wed Feb 8 03:31:24 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1