class ugcs::vsm::Log¶
Overview¶
Class for handling log output. More…
#include <log.h> class Log { public: // typedefs typedef ugcs::vsm::Param_exception<Exception_dummy_struct,> Exception; // enums enum Level; // structs struct Exception_dummy_struct; // classes class Platform_logger; // methods void Write_message_inst(Level level, const char* msg, ...); void Write_message_v_inst(Level level, const char* msg, std::va_list args); void Set_custom_log_inst(const std::string& log_file); void Set_max_custom_log_size_inst(ssize_t size); void Set_max_custom_log_count_inst(size_t count); static const char* Get_level_str(Level level); static std::string Get_basename(const char* path); static std::string Get_system_error(); static void Write_message(Level level, const char* msg, ...); static void Write_message_v(Level level, const char* msg, std::va_list args); static void Set_level(Level level); static void Set_level(const std::string& level); static void Set_custom_log(const std::string& log_file); static void Set_max_custom_log_size(const std::string& size_str); static void Set_max_custom_log_count(size_t count); };
Detailed Documentation¶
Class for handling log output.
A singleton object of this class is created when the first log output occurs. Log output is written to a custom log file (if set by the Set_custom_log method) and to the platform specific logging facilities (if present and implemented).
Methods¶
void Write_message_inst(Level level, const char* msg, ...)
Write formatted message to the log.
Parameters:
level |
Log level. |
msg |
Message format similar to format used in printf() function. |
void Write_message_v_inst(Level level, const char* msg, std::va_list args)
Write formatted message to the log.
Parameters:
level |
Log level. |
msg |
Message format similar to format used in printf() function. |
args |
Variable arguments list for format string. |
void Set_custom_log_inst(const std::string& log_file)
Set custom file path for the instance itself, behaves like Set_custom_log.
void Set_max_custom_log_size_inst(ssize_t size)
The same as Set_max_custom_log_size, but for the instance.
Parameters:
size |
Max size in bytes. |
void Set_max_custom_log_count_inst(size_t count)
Parameters:
size |
Max number of log files to keep. |
static const char* Get_level_str(Level level)
Convert level value to readable string.
static std::string Get_basename(const char* path)
Get base name (without leading directories) of file path.
static std::string Get_system_error()
Platform-dependent convenience method to get descriptive string for last system error.
static void Write_message(Level level, const char* msg, ...)
Write formatted message to the log.
Parameters:
level |
Log level. |
msg |
Message format similar to format used in printf() function. |
static void Write_message_v(Level level, const char* msg, std::va_list args)
Write formatted message to the log.
Parameters:
level |
Log level. |
msg |
Message format similar to format used in printf() function. |
args |
Variable arguments list for format string. |
static void Set_level(Level level)
Set current log level for the application.
Parameters:
level |
New global log level. |
static void Set_level(const std::string& level)
Set current log level.
Parameters:
level |
Level symbolic name. Valid names: error, warning, info, debug. |
Invalid_param_exception |
if invalid name specified. |
static void Set_custom_log(const std::string& log_file)
Set log file path for a custom (i.e.
non system standard) logging. Custom logging is disabled until file name is set.
Parameters:
log_file |
Full log file path. |
if log file could not be opened/created for appending. |
static void Set_max_custom_log_size(const std::string& size_str)
Set maximum size of a single custom log file.
When this size is reached, current log file is closed, re-named by appending a time stamp and a new custom log file is opened.
Parameters:
size_str |
Human readable size, which is a number postfixed with a case insensitive multiplier:
|
Invalid_param_exception |
exception if multiplier is not recognized. |
static void Set_max_custom_log_count(size_t count)
Set maximum number of log files to keep.
Older log files will be deleted.
Parameters:
count |
Number of old log files to keep. Default is 1. |