11 #ifndef _UGCS_VSM_LOG_H_
12 #define _UGCS_VSM_LOG_H_
61 static std::unique_ptr<Platform_logger>
146 Get_instance()->cur_level = level;
209 friend class Platform_logger;
212 constexpr
static ssize_t MIN_CUSTOM_LOG_FILE_SIZE = 16384;
215 constexpr
static ssize_t DEFAULT_MAX_CUSTOM_LOG_FILE_SIZE = 100 * 1024 * 1024;
218 constexpr
static const char*
const LOG_FILE_ROTATOR_SUFFIX_FORMAT =
"_%Y%m%d-%H%M%S";
223 constexpr
static const char*
const LOG_FILE_ROTATOR_FIND_PATTERN =
"_\?\?\?\?\?\?\?\?-\?\?\?\?\?\?*";
236 static volatile Log *log;
238 bool use_console =
true;
240 std::unique_ptr<Platform_logger> plat_logger;
242 std::string custom_log_file_name;
244 FILE* custom_log_file =
nullptr;
246 ssize_t max_custom_log = DEFAULT_MAX_CUSTOM_LOG_FILE_SIZE;
248 ssize_t custom_log_size;
251 size_t custom_log_count = 1;
259 Reopen_custom_log_file(
const std::string &log_file);
263 Write_custom_message(
int thread_id,
Log::Level level,
const char *msg,
264 std::va_list args)
__FORMAT(printf, 4, 0);
273 Write_console_message_inst(
int thread_id,
Level level,
const char *msg, ...)
__FORMAT(printf, 4, 5);
283 Write_console_message_v_inst(
int thread_id,
Level level, const
char *msg,
284 std::va_list args)
__FORMAT(printf, 4, 0);
293 Vprintf_utf8(const
char *format, std::va_list args)
__FORMAT(printf, 1, 0);
301 Printf_utf8(const
char *format, ...)
__FORMAT(printf, 1, 2);
309 Do_cleanup(
int thread_id);
313 Remove_old_log_files();
317 #define _LOG_WRITE_MSG(level, msg, ...) \
318 ::ugcs::vsm::Log::Write_message(level, "[%s:%d] " msg, \
319 ::ugcs::vsm::Log::Get_basename(__FILE__).c_str(), \
320 __LINE__, ## __VA_ARGS__)
323 #define LOG_DEBUG(msg, ...) \
324 _LOG_WRITE_MSG(::ugcs::vsm::Log::Level::DEBUGGING, msg, ## __VA_ARGS__)
327 #define LOG_DBG LOG_DEBUG
329 #define LOG LOG_DEBUG
332 #define LOG_INFO(msg, ...) \
333 _LOG_WRITE_MSG(::ugcs::vsm::Log::Level::INFO, msg, ## __VA_ARGS__)
336 #define LOG_WARNING(msg, ...) \
337 _LOG_WRITE_MSG(::ugcs::vsm::Log::Level::WARNING, msg, ## __VA_ARGS__)
340 #define LOG_WARN LOG_WARNING
343 #define LOG_ERROR(msg, ...) \
344 _LOG_WRITE_MSG(::ugcs::vsm::Log::Level::ERROR, msg, ## __VA_ARGS__)
347 #define LOG_ERR LOG_ERROR
static std::string Get_system_error()
Platform-dependent convenience method to get descriptive string for last system error.
Most verbose debug level.
static void Set_max_custom_log_size(const std::string &size_str)
Set maximum size of a single custom log file.
Class for handling log output.
Definition: log.h:33
Non-recoverable errors which should be noticed by an operator.
static void Set_custom_log(const std::string &log_file)
Set log file path for a custom (i.e.
Definition: log.h:164
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.
VSM exceptions definition.
Level
Available log levels.
Definition: log.h:39
static void Write_message_v(Level level, const char *msg, std::va_list args)
Write formatted message to the log.
void Set_max_custom_log_count_inst(size_t count)
static void Set_max_custom_log_count(size_t count)
Set maximum number of log files to keep.
#define __FORMAT(type, fmt_idx, arg_idx)
Specify that a function has format arguments (like printf or scanf).
Definition: defs.h:24
static void Write_message(Level level, const char *msg,...)
Write formatted message to the log.
void Write_message_v_inst(Level level, const char *msg, std::va_list args)
Write formatted message to the log.
static void Set_level(Level level)
Set current log level for the application.
Definition: log.h:141
void Set_custom_log_inst(const std::string &log_file)
Set custom file path for the instance itself, behaves like Set_custom_log.
Warning messages which should be noticed by an operator.
VSM_DEFINE_EXCEPTION(Exception)
Logging related exception.
void Set_max_custom_log_size_inst(ssize_t size)
The same as Set_max_custom_log_size, but for the instance.
void Write_message_inst(Level level, const char *msg,...)
Write formatted message to the log.
Base class for all VSM exceptions.
Definition: exception.h:22