MARLEY (Model of Argon Reaction Low Energy Yields)  v1.2.0
A Monte Carlo event generator for tens-of-MeV neutrino interactions
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
marley::Logger Class Reference

Simple singleton logging class. More...

#include <Logger.hh>

Public Types

enum class  LogLevel {
  DISABLED , ERROR , WARNING , INFO ,
  DEBUG
}
 Defines the logging levels recognized by the marley::Logger. More...
 

Public Member Functions

 Logger (const Logger &)=delete
 Deleted copy constructor.
 
 Logger (Logger &&)=delete
 Deleted move constructor.
 
void add_stream (std::ostream &stream, LogLevel level=LogLevel::WARNING)
 Add a std::ostream to the vector of streams that will receive Logger output. More...
 
void add_stream (std::shared_ptr< std::ostream > stream, LogLevel level=LogLevel::WARNING)
 Add a std::ostream to the vector of streams that will receive Logger output. More...
 
void clear_streams ()
 Clear the vector of streams that receive Logger output.
 
void disable ()
 Disable the Logger.
 
void enable (bool log_enabled=true)
 Enable or disable the Logger. More...
 
void flush ()
 Flush all output streams associated with the Logger.
 
bool has_stream (const std::ostream &stream) const
 Returns true if stream is already registered with the Logger, or false otherwise.
 
Message log (LogLevel lev=LogLevel::WARNING)
 Prepare the Logger to receive a log message via the << stream operator. More...
 
void newline ()
 Send a newline character to all output streams ignoring logging level settings.
 
Loggeroperator= (const Logger &)=delete
 Deleted copy assignment operator.
 
Loggeroperator= (Logger &&)=delete
 Deleted move assignment operator.
 

Static Public Member Functions

static LoggerInstance ()
 Get the singleton instance of the Logger class.
 

Detailed Description

Simple singleton logging class.

This class is based on code found here.

Member Enumeration Documentation

◆ LogLevel

Defines the logging levels recognized by the marley::Logger.

Note that C++ automatically assigns ascending values to the enum class members (which have an underlying integral type) in the order that they are written in the definition, so ERROR < WARNING < INFO < DEBUG.

Member Function Documentation

◆ add_stream() [1/2]

void marley::Logger::add_stream ( std::ostream &  stream,
LogLevel  level = LogLevel::WARNING 
)

Add a std::ostream to the vector of streams that will receive Logger output.

Note
For streams other than std::cout and std::cerr, using
See also
add_stream(std::shared_ptr<std::ostream> stream, LogLevel level) instead of this function is recommended. See also the documentation for
marley::Logger::OutStream::OutStream.

◆ add_stream() [2/2]

void marley::Logger::add_stream ( std::shared_ptr< std::ostream >  stream,
LogLevel  level = LogLevel::WARNING 
)

Add a std::ostream to the vector of streams that will receive Logger output.

Note
The stream owned by the std::shared_ptr should have been dynamically allocated since std::shared_ptr will auto-delete it when use_count falls to zero (unless a suitable custom deleter was used). For adding std::cout or std::cerr to the Logger, please use
See also
add_stream(std::ostream& stream, LogLevel level) instead. See also the documentation for
marley::Logger::OutStream::OutStream.

◆ enable()

void marley::Logger::enable ( bool  log_enabled = true)

Enable or disable the Logger.

Parameters
log_enabledEnable (true) or disable (false) the Logger

◆ log()

marley::Logger::Message marley::Logger::log ( LogLevel  lev = LogLevel::WARNING)

Prepare the Logger to receive a log message via the << stream operator.

Parameters
levmarley::Logger::LogLevel of the incoming message

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