OpenMS
LogConfigHandler Class Reference

The LogConfigHandler provides the functionality to configure the internal logging of OpenMS algorithms that use the global instances of LogStream. More...

#include <OpenMS/CONCEPT/LogConfigHandler.h>

Collaboration diagram for LogConfigHandler:
[legend]

Public Member Functions

Param parse (const StringList &setting)
 Translates the given list of parameter settings into a LogStream configuration. More...
 
void configure (const Param &param)
 Applies the given parameters (param) to the current configuration. More...
 
std::ostream & getStream (const String &stream_name)
 Returns a reference to the registered stream with the name stream_name. More...
 
void setLogLevel (const String &log_level)
 Sets a minimum log_level by removing all streams from loggers lower than that level. order of log_level: "DEBUG", "INFO", "WARNING", "ERROR", "FATAL_ERROR". More...
 
virtual ~LogConfigHandler ()
 Destructor. More...
 

Static Public Member Functions

static LogConfigHandlergetInstance ()
 Returns the instance of LogConfigHandler. More...
 

Static Public Attributes

static String PARAM_NAME
 Name of the parameter in which the configuration should be stored. More...
 

Protected Member Functions

Logger::LogStreamgetLogStreamByName_ (const String &stream_name)
 Returns the named global instance of the LogStream. (OpenMS::OpenMS_Log_debug, OpenMS::OpenMS_Log_info, OpenMS::OpenMS_Log_warn, OpenMS::OpenMS_Log_error, OpenMS::OpenMS_Log_fatal) More...
 
std::set< String > & getConfigSetByName_ (const String &stream_type)
 Returns the correct set of registered streams for the given stream type (e.g. DEBUG, INFO, ..) More...
 
StreamHandler::StreamType getStreamTypeByName_ (const String &stream_type)
 Translates the given stream_type String into a valid StreamHandler::StreamType. More...
 

Protected Attributes

std::set< Stringdebug_streams_
 List of all streams that were appended to OpenMS::OpenMS_Log_debug. More...
 
std::set< Stringinfo_streams_
 List of all streams that were appended to OpenMS::OpenMS_Log_info. More...
 
std::set< Stringwarn_streams_
 List of all streams that were appended to OpenMS::OpenMS_Log_warn. More...
 
std::set< Stringerror_streams_
 List of all streams that were appended to OpenMS::OpenMS_Log_error. More...
 
std::set< Stringfatal_streams_
 List of all streams that were appended to OpenMS::OpenMS_Log_fatal. More...
 
std::map< String, StreamHandler::StreamTypestream_type_map_
 Maps the registered streams to a StreamHandler::StreamType. More...
 

Private Member Functions

 LogConfigHandler ()
 Default constructor. More...
 
 LogConfigHandler (const LogConfigHandler &source)
 Copy constructor. More...
 
virtual LogConfigHandleroperator= (const LogConfigHandler &source)
 Assignment operator. More...
 

Static Private Attributes

static LogConfigHandlerinstance_
 

Friends

std::ostream & operator<< (std::ostream &os, LogConfigHandler const &lch)
 Overload for the insertion operator (operator<<) to have a formatted output of the LogConfigHandler. More...
 

Detailed Description

The LogConfigHandler provides the functionality to configure the internal logging of OpenMS algorithms that use the global instances of LogStream.

Constructor & Destructor Documentation

◆ ~LogConfigHandler()

virtual ~LogConfigHandler ( )
virtual

Destructor.

◆ LogConfigHandler() [1/2]

LogConfigHandler ( )
private

Default constructor.

◆ LogConfigHandler() [2/2]

LogConfigHandler ( const LogConfigHandler source)
private

Copy constructor.

Member Function Documentation

◆ configure()

void configure ( const Param param)

Applies the given parameters (param) to the current configuration.

<LOG_NAME> <ACTION> <PARAMETER> <STREAMTYPE>

LOG_NAME: DEBUG,INFO,WARNING,ERROR,FATAL_ERROR ACTION: add,remove,clear PARAMETER: for 'add'/'remove' it is the stream name (cout, cerr or a filename), 'clear' does not require any further parameter STREAMTYPE: FILE, STRING (for a StringStream, which you can grab by this name using getStream() )

You cannot specify a file named "cout" or "cerr" even if you specify streamtype 'FILE' - the handler will mistake this for the internal streams, but you can use "./cout" to print to a file named cout.

A classical configuration would contain a list of settings e.g.

DEBUG add debug.log FILE
INFO remove cout FILE (FILE will be ignored)
INFO add string_stream1 STRING

Exceptions
Exception::ElementNotFoundIf the LogStream (first argument) does not exist.
Exception::FileNotWritableIf a file (or stream) should be opened as log file (or stream) that is not accessible.
Exception::IllegalArgumentIf a stream should be registered, that was already registered with a different type.

◆ getConfigSetByName_()

std::set<String>& getConfigSetByName_ ( const String stream_type)
protected

Returns the correct set of registered streams for the given stream type (e.g. DEBUG, INFO, ..)

Parameters
stream_typeString representation of the stream type (DEBUG, INFO, ..)
Exceptions
ElementNotFoundExceptionif the given stream_type does not correspond to one of the known LogStreams

◆ getInstance()

static LogConfigHandler* getInstance ( )
static

Returns the instance of LogConfigHandler.

◆ getLogStreamByName_()

Logger::LogStream& getLogStreamByName_ ( const String stream_name)
protected

Returns the named global instance of the LogStream. (OpenMS::OpenMS_Log_debug, OpenMS::OpenMS_Log_info, OpenMS::OpenMS_Log_warn, OpenMS::OpenMS_Log_error, OpenMS::OpenMS_Log_fatal)

Parameters
stream_nameName of the stream. Should be DEBUG,INFO,WARNING,ERROR,FATAL_ERROR.
Exceptions
ElementNotFoundExceptionif the given stream_name does not correspond to one of the known LogStream instances
Returns
A reference to the named LogStream

◆ getStream()

std::ostream& getStream ( const String stream_name)

Returns a reference to the registered stream with the name stream_name.

Exceptions
Exception::IllegalArgumentIf no stream with the name stream_name was registered before.
Returns
Reference to the stream.

◆ getStreamTypeByName_()

StreamHandler::StreamType getStreamTypeByName_ ( const String stream_type)
protected

Translates the given stream_type String into a valid StreamHandler::StreamType.

Parameters
stream_typeString representation of the StreamHandler::StreamType
Exceptions
Exception::IllegalArgumentis thrown when the passed stream_type does not correspond to an existing StreamHandler::StreamType
Returns
The requested StreamHandler::StreamType

◆ operator=()

virtual LogConfigHandler& operator= ( const LogConfigHandler source)
privatevirtual

Assignment operator.

◆ parse()

Param parse ( const StringList setting)

Translates the given list of parameter settings into a LogStream configuration.

Translates the given list of parameter settings into a LogStream configuration. Usually this list stems from a command line call.

Each element in the stringlist should follow this naming convention

<LOG_NAME> <ACTION> <PARAMETER>

with LOG_NAME: DEBUG,INFO,WARNING,ERROR,FATAL_ERROR ACTION: add,remove,clear PARAMETER: for 'add'/'remove' it is the stream name (cout, cerr or a filename), 'clear' does not require any further parameter

Example: DEBUG add debug.log

This function will not apply to settings to the log handlers. Use configure() for that.

Parameters
settingStringList containing the configuration options
Exceptions
Exception::ParseErrorIn case of an invalid configuration.
Returns
Param object containing all settings, that can be applied using the LogConfigHandler::configure() method

◆ setLogLevel()

void setLogLevel ( const String log_level)

Sets a minimum log_level by removing all streams from loggers lower than that level. order of log_level: "DEBUG", "INFO", "WARNING", "ERROR", "FATAL_ERROR".

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
LogConfigHandler const &  lch 
)
friend

Overload for the insertion operator (operator<<) to have a formatted output of the LogConfigHandler.

Member Data Documentation

◆ debug_streams_

std::set<String> debug_streams_
protected

List of all streams that were appended to OpenMS::OpenMS_Log_debug.

◆ error_streams_

std::set<String> error_streams_
protected

List of all streams that were appended to OpenMS::OpenMS_Log_error.

◆ fatal_streams_

std::set<String> fatal_streams_
protected

List of all streams that were appended to OpenMS::OpenMS_Log_fatal.

◆ info_streams_

std::set<String> info_streams_
protected

List of all streams that were appended to OpenMS::OpenMS_Log_info.

◆ instance_

LogConfigHandler* instance_
staticprivate

◆ PARAM_NAME

String PARAM_NAME
static

Name of the parameter in which the configuration should be stored.

◆ stream_type_map_

std::map<String, StreamHandler::StreamType> stream_type_map_
protected

Maps the registered streams to a StreamHandler::StreamType.

◆ warn_streams_

std::set<String> warn_streams_
protected

List of all streams that were appended to OpenMS::OpenMS_Log_warn.