![]() |
HAL
|
#include <log.h>
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 () |
ProgramOptions & | get_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 LogManager * | get_instance (const std::filesystem::path &file_name="") |
static std::shared_ptr< log_sink > | create_stdout_sink (const bool colored=true) |
static std::shared_ptr< log_sink > | create_file_sink (const std::filesystem::path &file_name="", const bool truncate=false) |
static std::shared_ptr< log_sink > | create_gui_sink () |
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().
void hal::LogManager::activate_channel | ( | const std::string & | channel_name | ) |
Activate a channel.
By default all channels are active.
[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().
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.
[in] | channel_name | - Name of the channel. |
[in] | sinks | - All sinks connected to this channel. |
[in] | level | - The severity level of that 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().
|
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.
[in] | file_name | - The file name. |
[in] | truncate | - Flag whether the file should be overwritten(true) or appended to(false). |
Definition at line 247 of file log.cpp.
References get_instance().
Referenced by hal::initialize(), hal::BasePluginInterface::initialize_logging(), and set_file_name().
|
static |
Create a new logging sink which prints to the GUI.
Definition at line 274 of file log.cpp.
Referenced by hal::initialize(), and hal::BasePluginInterface::initialize_logging().
|
static |
Create a new logging sink which prints to stdout.
[in] | colored | - If true, the output will be colored depending on the severity. |
Definition at line 216 of file log.cpp.
References log_error.
Referenced by hal::initialize(), and hal::BasePluginInterface::initialize_logging().
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().
void hal::LogManager::deactivate_channel | ( | const std::string & | channel_name | ) |
Deactivate a channel suppressing all output.
[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().
std::set< std::string > hal::LogManager::get_available_log_levels | ( | ) | const |
Get all available severity levels.
Definition at line 283 of file log.cpp.
Referenced by hal::log_init().
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.
[in] | channel_name | - Name of the channel. |
Definition at line 75 of file log.cpp.
References add_channel(), and log_warning.
Referenced by hal::log_init().
std::set< std::string > hal::LogManager::get_channels | ( | ) | const |
Returns all channels' names.
Definition at line 90 of file log.cpp.
Referenced by get_option_descriptions(), handle_options(), and hal::log_init().
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.
Definition at line 204 of file log.cpp.
Referenced by hal::log_init().
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.
Definition at line 431 of file log.cpp.
Referenced by hal::log_gui_sink::sink_it_(), and hal::ChannelModel::~ChannelModel().
|
static |
Get the log manager instance.
If the desired log file is left empty, the default log path is used.
(Singleton pattern)
[in] | file_name | - The file where the log is stored. |
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().
std::string hal::LogManager::get_level_of_channel | ( | const std::string & | channel_name | ) | const |
Get a channel's severity level.
[in] | channel_name | - Name of the channel. |
Definition at line 145 of file log.cpp.
Referenced by set_file_name().
ProgramOptions & hal::LogManager::get_option_descriptions | ( | ) |
Get the program options for the logging system.
Definition at line 353 of file log.cpp.
References hal::ProgramOptions::A_REQUIRED_PARAMETER, hal::ProgramOptions::add(), get_channels(), and hal::ProgramOptions::get_options().
void hal::LogManager::handle_options | ( | ProgramArguments & | args | ) |
Handle parsed program options for the logging system.
[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().
void hal::LogManager::remove_channel | ( | const std::string & | channel_name | ) |
Remove a channel from the log manager.
[in] | channel_name | - Name of the channel. |
Definition at line 133 of file log.cpp.
Referenced by set_file_name().
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.
[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().
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.
[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().
void hal::LogManager::set_format_pattern | ( | const std::string & | format | ) |
void hal::LogManager::set_level_of_channel | ( | const std::string & | channel_name, |
const std::string & | level | ||
) |
Set a channel's severity level.
[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().