VSM C++ SDK
Vehicle Specific Modules SDK
ugcs::vsm::Log Class Reference

Class for handling log output. More...

#include <log.h>

Classes

struct  Exception_dummy_struct
 Logging related exception. More...
 
class  Platform_logger
 Platform-specific logging handler. More...
 

Public Types

enum  Level {
  Level::DEBUGGING, Level::INFO, Level::WARNING, Level::ERROR,
  Level::MAX = ERROR
}
 Available log levels. More...
 
typedef ugcs::vsm::Param_exception< Exception_dummy_struct,> Exception
 

Public Member Functions

 Log ()
 Constructor. More...
 
 ~Log ()
 Destructor. More...
 
void Write_message_inst (Level level, const char *msg,...)
 Write formatted message to the log. More...
 
void Write_message_v_inst (Level level, const char *msg, std::va_list args)
 Write formatted message to the log. More...
 
void Set_custom_log_inst (const std::string &log_file)
 Set custom file path for the instance itself, behaves like Set_custom_log. More...
 
void Set_max_custom_log_size_inst (ssize_t size)
 The same as Set_max_custom_log_size, but for the instance. More...
 
void Set_max_custom_log_count_inst (size_t count)
 

Static Public Member Functions

static const char * Get_level_str (Level level)
 Convert level value to readable string. More...
 
static std::string Get_basename (const char *path)
 Get base name (without leading directories) of file path. More...
 
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. More...
 
static void Write_message_v (Level level, const char *msg, std::va_list args)
 Write formatted message to the log. More...
 
static void Set_level (Level level)
 Set current log level for the application. More...
 
static void Set_level (const std::string &level)
 Set current log level. More...
 
static void Set_custom_log (const std::string &log_file)
 Set log file path for a custom (i.e. More...
 
static void Set_max_custom_log_size (const std::string &size_str)
 Set maximum size of a single custom log file. More...
 
static void Set_max_custom_log_count (size_t count)
 Set maximum number of log files to keep. More...
 

Friends

class Platform_logger
 

Detailed Description

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).

Member Enumeration Documentation

enum ugcs::vsm::Log::Level
strong

Available log levels.

Enumerator
DEBUGGING 

Most verbose debug level.

Should be used only for debug information output.

INFO 

Informational messages.

WARNING 

Warning messages which should be noticed by an operator.

The error condition should be recoverable.

ERROR 

Non-recoverable errors which should be noticed by an operator.

MAX 

Maximal level code.

Constructor & Destructor Documentation

ugcs::vsm::Log::Log ( )

Constructor.

ugcs::vsm::Log::~Log ( )

Destructor.

Member Function Documentation

static std::string ugcs::vsm::Log::Get_basename ( const char *  path)
static

Get base name (without leading directories) of file path.

static const char* ugcs::vsm::Log::Get_level_str ( Level  level)
static

Convert level value to readable string.

static void ugcs::vsm::Log::Set_custom_log ( const std::string &  log_file)
inlinestatic

Set log file path for a custom (i.e.

non system standard) logging. Custom logging is disabled until file name is set.

Parameters
log_fileFull log file path.
Exceptions
Log::Exceptionif log file could not be opened/created for appending.
void ugcs::vsm::Log::Set_custom_log_inst ( const std::string &  log_file)

Set custom file path for the instance itself, behaves like Set_custom_log.

static void ugcs::vsm::Log::Set_level ( Level  level)
inlinestatic

Set current log level for the application.

Parameters
levelNew global log level.
static void ugcs::vsm::Log::Set_level ( const std::string &  level)
static

Set current log level.

Parameters
levelLevel symbolic name. Valid names: error, warning, info, debug.
Exceptions
Invalid_param_exceptionif invalid name specified.
static void ugcs::vsm::Log::Set_max_custom_log_count ( size_t  count)
static

Set maximum number of log files to keep.

Older log files will be deleted.

Parameters
countNumber of old log files to keep. Default is 1.
void ugcs::vsm::Log::Set_max_custom_log_count_inst ( size_t  count)
Parameters
sizeMax number of log files to keep.
static void ugcs::vsm::Log::Set_max_custom_log_size ( const std::string &  size_str)
static

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_strHuman readable size, which is a number postfixed with a case insensitive multiplier:
  • Gb, G, Gbyte, Gbytes - for Giga-bytes;
  • Mb, M, Mbyte, Mbytes - for Mega-bytes;
  • Kb, K, Kbyte, Kbytes - for Kilo-bytes;
  • no postfix - for bytes;
Exceptions
Invalid_param_exceptionexception if multiplier is not recognized.
void ugcs::vsm::Log::Set_max_custom_log_size_inst ( ssize_t  size)

The same as Set_max_custom_log_size, but for the instance.

Parameters
sizeMax size in bytes.
static void ugcs::vsm::Log::Write_message ( Level  level,
const char *  msg,
  ... 
)
static

Write formatted message to the log.

Parameters
levelLog level.
msgMessage format similar to format used in printf() function.
void ugcs::vsm::Log::Write_message_inst ( Level  level,
const char *  msg,
  ... 
)

Write formatted message to the log.

Parameters
levelLog level.
msgMessage format similar to format used in printf() function.
static void ugcs::vsm::Log::Write_message_v ( Level  level,
const char *  msg,
std::va_list  args 
)
static

Write formatted message to the log.

Parameters
levelLog level.
msgMessage format similar to format used in printf() function.
argsVariable arguments list for format string.
void ugcs::vsm::Log::Write_message_v_inst ( Level  level,
const char *  msg,
std::va_list  args 
)

Write formatted message to the log.

Parameters
levelLog level.
msgMessage format similar to format used in printf() function.
argsVariable arguments list for format string.

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