Static Public Member Functions | List of all members
gnsstk::ConfigureLOGstream Class Reference

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)

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

// (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
// 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
// optionally, also change the max level
// ...

Definition at line 274 of file logstream.hpp.

#include <logstream.hpp>

Static Public Member Functions

static void Output (const std::string &msg)
 used internally More...
 
static std::ostream *& Stream ()
 

Member Function Documentation

◆ Output()

void gnsstk::ConfigureLOGstream::Output ( const std::string &  msg)
inlinestatic

used internally

Definition at line 294 of file logstream.hpp.

◆ Stream()

std::ostream *& gnsstk::ConfigureLOGstream::Stream ( )
inlinestatic

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

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

Definition at line 288 of file logstream.hpp.


The documentation for this class was generated from the following file:
logstream.hpp
gnsstk::WARNING
@ WARNING
Definition: logstream.hpp:57
gnsstk::ConfigureLOG::Level
static LogLevel Level(const std::string &str)
Definition: logstream.hpp:308
gnsstk::Log< ConfigureLOGstream >::ReportingLevel
static LogLevel & ReportingLevel()
get/set the highest level that is actually output to log stream
Definition: logstream.hpp:134
gnsstk::ERROR
@ ERROR
Definition: logstream.hpp:57
gnsstk::VERBOSE
@ VERBOSE
Definition: logstream.hpp:57
gnsstk::ConfigureLOG::Stream
static std::ostream *& Stream()
Definition: logstream.hpp:306
LOG
#define LOG(level)
define the macro that is used to write to the log stream
Definition: logstream.hpp:315
gnsstk::INFO
@ INFO
Definition: logstream.hpp:57
gnsstk::DEBUG6
@ DEBUG6
Definition: logstream.hpp:58
gnsstk::Log< ConfigureLOGstream >::ReportLevels
static bool & ReportLevels()
get/set; if true, output level on each line, after the time tag
Definition: logstream.hpp:118
gnsstk::ConfigureLOGstream::Stream
static std::ostream *& Stream()
Definition: logstream.hpp:288
gnsstk::Log< ConfigureLOGstream >::ReportTimeTags
static bool & ReportTimeTags()
get/set; if true, output time tag on each line, first
Definition: logstream.hpp:126


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44