Class ConsoleHandler

Class Documentation

class ConsoleHandler

ConsoleHandler class is a wrapper around plog initialization, i.e. encapsulates log configuration and initialization.

Public Functions

ConsoleHandler(const ConsoleHandler&) = delete
ConsoleHandler &operator=(const ConsoleHandler&) = delete
virtual void initialize(const std::string &welcome_msg)

Initializes plog instance, configures logging to console and file, generates an unique file name and prints out first wecome message.

Parameters

welcome_msg[in] The very first message in logs (info level)

inline virtual void set_severity(const plog::Severity &severity)

Sets severity level, which is passed to plog instance. Has effect only before calling initialize() method.

Parameters

severity[in] plog severity level

inline virtual plog::Severity get_severity() const

Gets severity level used for plog initialization.

Returns

plog severity level

inline virtual void use_colors(bool flag = true)

Sets a flag for coloring an output of logs (used only for console). Has effect only before calling initialize() method.

Parameters

flag[in] true for colored output, false otherwise

inline virtual bool colored_console() const

Return coloring flag, used for plog initialization.

Returns

true for colored output, false otherwise

inline virtual void set_log_directory(const std::string &dirpath)

Overrides default location for logs output. Has effect only before calling initialize() method.

See also

initialize()

Parameters

dirpath[in] path to directory

inline virtual std::string get_log_directory() const

Return log directory path.

Returns

path as string

inline virtual std::string get_log_filename() const

Returns name of log file.

inline virtual std::string get_log_filepath() const

Returns a full path to log file.

Returns

path as string

inline virtual bool log_directory_created() const

Inform whether directory was created for log file.

Returns

true if new directory created, false otherwise

inline virtual bool is_initialized() const

Returns true if plog instance was initialized.

Public Members

ServerAppender server_appender_

Public Static Functions

static inline ConsoleHandler &get_instance()

Returns a reference to singleton instance of the ConsoleHandler class.

Protected Functions

virtual std::string _get_log_filename() const

Generates an unique log filename.

Returns

unique name of log file

virtual bool _initialize_log_location(const std::string &filename, std::string &error_msg)

Inititlizes log file location, either the default location, defined in SmartPeak::Utilities::getLogFilepath(), or location given by set_log_directory().

Returns

true if initialization correct, false otherwise

virtual void _initialize_log_console(bool init_file_appender = true)

Inititlizes plog instance, configures console and file appender. Colored console appender is used if use_colors() set the flag to true. If init_file_appender is set to false, it will only use console appender.

See also

use_colors()

Parameters

init_file_appender – set to true if location is correct, false otherwise