HAL
hal::LogManager Class Reference

#include <log.h>

Collaboration diagram for hal::LogManager:
Collaboration graph

Classes

struct  log_sink
 

Public Member Functions

void set_file_name (const std::filesystem::path &file_name)
 
void set_format_pattern (const std::string &format)
 
std::shared_ptr< spdlog::logger > get_channel (const std::string &channel_name="stdout")
 
std::set< std::string > get_channels () const
 
std::shared_ptr< spdlog::logger > add_channel (const std::string &channel_name, const std::vector< std::shared_ptr< log_sink >> &sinks, const std::string &level="info")
 
void remove_channel (const std::string &channel_name)
 
std::string get_level_of_channel (const std::string &channel_name) const
 
void set_level_of_channel (const std::string &channel_name, const std::string &level)
 
std::set< std::string > get_available_log_levels () const
 
void activate_channel (const std::string &channel_name)
 
void activate_all_channels ()
 
void deactivate_channel (const std::string &channel_name)
 
void deactivate_all_channels ()
 
CallbackHook< void(const spdlog::level::level_enum &, const std::string &, const std::string &)> & get_gui_callback ()
 
ProgramOptionsget_option_descriptions ()
 
void handle_options (ProgramArguments &args)
 
std::vector< std::shared_ptr< hal::LogManager::log_sink > > get_default_sinks ()
 
void remove_sink_from_default (const std::string &sink_type)
 

Static Public Member Functions

static LogManagerget_instance (const std::filesystem::path &file_name="")
 
static std::shared_ptr< log_sinkcreate_stdout_sink (const bool colored=true)
 
static std::shared_ptr< log_sinkcreate_file_sink (const std::filesystem::path &file_name="", const bool truncate=false)
 
static std::shared_ptr< log_sinkcreate_gui_sink ()
 

Detailed Description

Definition at line 104 of file log.h.

Member Function Documentation

◆ activate_all_channels()

void hal::LogManager::activate_all_channels ( )

Activate all logging channels.

Definition at line 183 of file log.cpp.

References set_level_of_channel().

Referenced by hal::log_init().

◆ activate_channel()

void hal::LogManager::activate_channel ( const std::string &  channel_name)

Activate a channel.
By default all channels are active.

Parameters
[in]channel_name- The name of the channel.

Definition at line 178 of file log.cpp.

References set_level_of_channel().

Referenced by handle_options(), and hal::log_init().

◆ add_channel()

std::shared_ptr< spdlog::logger > hal::LogManager::add_channel ( const std::string &  channel_name,
const std::vector< std::shared_ptr< log_sink >> &  sinks,
const std::string &  level = "info" 
)

Add a channel to the log manager.

Parameters
[in]channel_name- Name of the channel.
[in]sinks- All sinks connected to this channel.
[in]level- The severity level of that channel.
Returns
A pointer to the channel.

Definition at line 100 of file log.cpp.

References set_level_of_channel().

Referenced by get_channel(), hal::initialize(), hal::BasePluginInterface::initialize_logging(), and set_file_name().

◆ create_file_sink()

std::shared_ptr< LogManager::log_sink > hal::LogManager::create_file_sink ( const std::filesystem::path &  file_name = "",
const bool  truncate = false 
)
static

Create a new logging sink which prints to a file.
If a sink for that file already exists, no new sink will be created.
If file_name is empty, the default log file will be used.

Parameters
[in]file_name- The file name.
[in]truncate- Flag whether the file should be overwritten(true) or appended to(false).
Returns
The new sink or the already existing sink.

Definition at line 247 of file log.cpp.

References get_instance().

Referenced by hal::initialize(), hal::BasePluginInterface::initialize_logging(), and set_file_name().

◆ create_gui_sink()

std::shared_ptr< LogManager::log_sink > hal::LogManager::create_gui_sink ( )
static

Create a new logging sink which prints to the GUI.

Returns
The new sink.

Definition at line 274 of file log.cpp.

Referenced by hal::initialize(), and hal::BasePluginInterface::initialize_logging().

◆ create_stdout_sink()

std::shared_ptr< LogManager::log_sink > hal::LogManager::create_stdout_sink ( const bool  colored = true)
static

Create a new logging sink which prints to stdout.

Parameters
[in]colored- If true, the output will be colored depending on the severity.
Returns
The new sink.

Definition at line 216 of file log.cpp.

References log_error.

Referenced by hal::initialize(), and hal::BasePluginInterface::initialize_logging().

◆ deactivate_all_channels()

void hal::LogManager::deactivate_all_channels ( )

Deactivate all logging channels.

Definition at line 196 of file log.cpp.

References set_level_of_channel().

Referenced by hal::log_init().

◆ deactivate_channel()

void hal::LogManager::deactivate_channel ( const std::string &  channel_name)

Deactivate a channel suppressing all output.

Parameters
[in]channel_name- The name of the channel.

Definition at line 191 of file log.cpp.

References set_level_of_channel().

Referenced by handle_options(), and hal::log_init().

◆ get_available_log_levels()

std::set< std::string > hal::LogManager::get_available_log_levels ( ) const

Get all available severity levels.

Returns
A set of severity levels.

Definition at line 283 of file log.cpp.

Referenced by hal::log_init().

◆ get_channel()

std::shared_ptr< spdlog::logger > hal::LogManager::get_channel ( const std::string &  channel_name = "stdout")

Get a channel specified by name. Creates the channel if it does not exist yet.

Parameters
[in]channel_name- Name of the channel.
Returns
A pointer to the channel.

Definition at line 75 of file log.cpp.

References add_channel(), and log_warning.

Referenced by hal::log_init().

◆ get_channels()

std::set< std::string > hal::LogManager::get_channels ( ) const

Returns all channels' names.

Returns
A set of the names.

Definition at line 90 of file log.cpp.

Referenced by get_option_descriptions(), handle_options(), and hal::log_init().

◆ get_default_sinks()

std::vector< std::shared_ptr< hal::LogManager::log_sink > > hal::LogManager::get_default_sinks ( )

Get the vector of default sinks that are added to each newly created logger by default.

Returns
The default sinks.

Definition at line 204 of file log.cpp.

Referenced by hal::log_init().

◆ get_gui_callback()

CallbackHook< void(const spdlog::level::level_enum &, const std::string &, const std::string &)> & hal::LogManager::get_gui_callback ( )

Get the GUI callback hook for displaying log messages inside the GUI.

Returns
The GUI callback hook for (level, channel, message).

Definition at line 431 of file log.cpp.

Referenced by hal::log_gui_sink::sink_it_(), and hal::ChannelModel::~ChannelModel().

◆ get_instance()

LogManager * hal::LogManager::get_instance ( const std::filesystem::path &  file_name = "")
static

Get the log manager instance.
If the desired log file is left empty, the default log path is used.
(Singleton pattern)

Parameters
[in]file_name- The file where the log is stored.
Returns
The log manager.

Definition at line 61 of file log.cpp.

Referenced by create_file_sink(), hal::initialize(), hal::BasePluginInterface::initialize_logging(), hal::log_init(), hal::log_gui_sink::sink_it_(), and hal::ChannelModel::~ChannelModel().

◆ get_level_of_channel()

std::string hal::LogManager::get_level_of_channel ( const std::string &  channel_name) const

Get a channel's severity level.

Parameters
[in]channel_name- Name of the channel.
Returns
The severity level of that channel.

Definition at line 145 of file log.cpp.

Referenced by set_file_name().

◆ get_option_descriptions()

ProgramOptions & hal::LogManager::get_option_descriptions ( )

Get the program options for the logging system.

Returns
The program options.

Definition at line 353 of file log.cpp.

References hal::ProgramOptions::A_REQUIRED_PARAMETER, hal::ProgramOptions::add(), get_channels(), and hal::ProgramOptions::get_options().

◆ handle_options()

void hal::LogManager::handle_options ( ProgramArguments args)

Handle parsed program options for the logging system.

Parameters
[in]args- The parsed program options.

Definition at line 374 of file log.cpp.

References activate_channel(), control::args, deactivate_channel(), get_channels(), log_warning, and set_level_of_channel().

◆ remove_channel()

void hal::LogManager::remove_channel ( const std::string &  channel_name)

Remove a channel from the log manager.

Parameters
[in]channel_name- Name of the channel.

Definition at line 133 of file log.cpp.

Referenced by set_file_name().

◆ remove_sink_from_default()

void hal::LogManager::remove_sink_from_default ( const std::string &  sink_type)

Remove the specified sink type from the vector of default sinks if present.

Parameters
[in]sink_type- The type of sink to remove from default sinks.

Definition at line 209 of file log.cpp.

Referenced by hal::log_init().

◆ set_file_name()

void hal::LogManager::set_file_name ( const std::filesystem::path &  file_name)

Set the log file name.
If file_name is empty, the default log file will be used.

Parameters
[in]file_name- The desired log file.

Definition at line 291 of file log.cpp.

References add_channel(), create_file_sink(), get_level_of_channel(), log_info, name, and remove_channel().

Referenced by hal::log_init().

◆ set_format_pattern()

void hal::LogManager::set_format_pattern ( const std::string &  format)

Set the logging format pattern.
Look at the speedlog documentation to get details about the format string.

Parameters
[in]format- The format string.

Definition at line 70 of file log.cpp.

◆ set_level_of_channel()

void hal::LogManager::set_level_of_channel ( const std::string &  channel_name,
const std::string &  level 
)

Set a channel's severity level.

Parameters
[in]channel_name- Name of the channel.
[in]level- The severity level.

Definition at line 164 of file log.cpp.

Referenced by activate_all_channels(), activate_channel(), add_channel(), deactivate_all_channels(), deactivate_channel(), handle_options(), and hal::log_init().


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