Virgil IoT KIT
|
Logger implementation. More...
#include <logger-config.h>
#include <stdarg.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib-config.h>
Go to the source code of this file.
Macros | |
#define | __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
#define | VS_LOG_GET_LOGLEVEL(LOGLEV_VARIABLE) (LOGLEV_VARIABLE) = vs_logger_get_loglev() |
Get current logging level to LOGLEV_VARIABLE. More... | |
#define | VS_LOG_IS_LOGLEVEL(LOGLEV_VALUE) vs_logger_is_loglev(LOGLEV_VALUE) |
Is LOGLEV_VALUE logging level is enabled. More... | |
#define | VS_LOG_SET_LOGLEVEL(LOGLEV_VALUE) vs_logger_set_loglev(LOGLEV_VALUE) |
Set LOGLEV_VALUE as current logging level. More... | |
#define | VS_LOG(LGLVL, FRMT, ...) vs_logger_message((LGLVL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message. More... | |
#define | VS_LOG_HEX(LGLVL, PREFIX, BUF, SIZE) vs_logger_message_hex((LGLVL), __FILENAME__, __LINE__, (PREFIX), (BUF), (SIZE)) |
Log HEX buffer. More... | |
#define | VS_LOG_MAKE_LEVEL(LEVEL) LEVEL |
#define | VS_LOG_INFO(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_INFO), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_INFO level. More... | |
#define | VS_LOG_FATAL(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_FATAL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_FATAL level. More... | |
#define | VS_LOG_ALERT(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_ALERT), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_ALERT level. More... | |
#define | VS_LOG_CRITICAL(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_CRITICAL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_CRITICAL level. More... | |
#define | VS_LOG_ERROR(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_ERROR), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_ERROR level. More... | |
#define | VS_LOG_WARNING(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_WARNING), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_WARNING level. More... | |
#define | VS_LOG_NOTICE(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_NOTICE), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_NOTICE level. More... | |
#define | VS_LOG_TRACE(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_TRACE), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_TRACE level. More... | |
#define | VS_LOG_DEBUG(FRMT, ...) vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_DEBUG), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_DEBUG level. More... | |
Enumerations | |
enum | vs_log_level_t { VS_LOGLEV_UNKNOWN = 0xFF, VS_LOGLEV_NO_LOGGER = 0xFE, VS_LOGLEV_INFO = 0x00, VS_LOGLEV_FATAL = 0x10, VS_LOGLEV_ALERT = 0x20, VS_LOGLEV_CRITICAL = 0x30, VS_LOGLEV_ERROR = 0x40, VS_LOGLEV_WARNING = 0x50, VS_LOGLEV_NOTICE = 0x60, VS_LOGLEV_TRACE = 0x70, VS_LOGLEV_DEBUG = 0xFD } |
Logging level. More... | |
Functions | |
bool | vs_log_thread_descriptor (const char *description) |
Set current thread description. More... | |
bool | vs_logger_last_result (void) |
Last result. More... | |
void | vs_logger_message (vs_log_level_t level, const char *cur_filename, uint32_t line_num, const char *log_format,...) |
Log text message. More... | |
void | vs_logger_init (vs_log_level_t log_level) |
Initialize logging level. More... | |
vs_log_level_t | vs_logger_set_loglev (vs_log_level_t new_level) |
Set current logging level. More... | |
vs_log_level_t | vs_logger_get_loglev (void) |
Get current logging level. More... | |
bool | vs_logger_is_loglev (vs_log_level_t level) |
Check that specified logging level is enabled. More... | |
void | vs_logger_message_hex (vs_log_level_t level, const char *cur_filename, uint32_t line_num, const char *prefix, const void *data_buf, const uint16_t data_size) |
Log HEX buffer. More... | |
Logger implementation.
Logger allows to log messages to output stream that can be file or screen. User can enable different logging levels like debug, info, error etc. (see vs_log_level_t). In future versions sending report through network is planned
See the following snippet for the logger usage examples :
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) |
#define VS_LOG | ( | LGLVL, | |
FRMT, | |||
... | |||
) | vs_logger_message((LGLVL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message.
Sends FRMT message by calling vs_logger_message function.
[in] | LGLVL | Logging level. |
[in] | FRMT | printf-like format string and arguments. |
#define VS_LOG_ALERT | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_ALERT), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_ALERT level.
#define VS_LOG_CRITICAL | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_CRITICAL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_CRITICAL level.
#define VS_LOG_DEBUG | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_DEBUG), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_DEBUG level.
#define VS_LOG_ERROR | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_ERROR), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_ERROR level.
#define VS_LOG_FATAL | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_FATAL), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_FATAL level.
#define VS_LOG_GET_LOGLEVEL | ( | LOGLEV_VARIABLE | ) | (LOGLEV_VARIABLE) = vs_logger_get_loglev() |
Get current logging level to LOGLEV_VARIABLE.
#define VS_LOG_HEX | ( | LGLVL, | |
PREFIX, | |||
BUF, | |||
SIZE | |||
) | vs_logger_message_hex((LGLVL), __FILENAME__, __LINE__, (PREFIX), (BUF), (SIZE)) |
Log HEX buffer.
Sends BUF as hex string by calling vs_logger_message function.
[in] | LGLVL | Logging level |
[in] | PREFIX | Prefix for output. Must not be NULL. |
[in] | BUF | Buffer to be output as HEX. Must not be NULL. |
[in] | SIZE | Size of the array to be output as HEX. Must not be zero. |
#define VS_LOG_INFO | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_INFO), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_INFO level.
#define VS_LOG_IS_LOGLEVEL | ( | LOGLEV_VALUE | ) | vs_logger_is_loglev(LOGLEV_VALUE) |
Is LOGLEV_VALUE logging level is enabled.
#define VS_LOG_MAKE_LEVEL | ( | LEVEL | ) | LEVEL |
#define VS_LOG_NOTICE | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_NOTICE), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_NOTICE level.
#define VS_LOG_SET_LOGLEVEL | ( | LOGLEV_VALUE | ) | vs_logger_set_loglev(LOGLEV_VALUE) |
Set LOGLEV_VALUE as current logging level.
#define VS_LOG_TRACE | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_TRACE), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_TRACE level.
#define VS_LOG_WARNING | ( | FRMT, | |
... | |||
) | vs_logger_message(VS_LOG_MAKE_LEVEL(VS_LOGLEV_WARNING), __FILENAME__, __LINE__, (FRMT), ##__VA_ARGS__) |
Log message with VS_LOGLEV_WARNING level.
enum vs_log_level_t |
Logging level.
bool vs_log_thread_descriptor | ( | const char * | description | ) |
Set current thread description.
description | Human readable thread description. |
vs_log_level_t vs_logger_get_loglev | ( | void | ) |
Get current logging level.
void vs_logger_init | ( | vs_log_level_t | log_level | ) |
Initialize logging level.
log_level is initialized and default title for thread is provided. You can change this name by vs_log_thread_descriptor call
[int] | log_level Message log level |
bool vs_logger_is_loglev | ( | vs_log_level_t | level | ) |
Check that specified logging level is enabled.
[in] | level | Logging level to be tested |
bool vs_logger_last_result | ( | void | ) |
Last result.
Return true if there were no errors during last call and log level was appropriate.
void vs_logger_message | ( | vs_log_level_t | level, |
const char * | cur_filename, | ||
uint32_t | line_num, | ||
const char * | log_format, | ||
... | |||
) |
Log text message.
Sends FRMT output message with current time if VS_IOT_LOGGER_OUTPUT_TIME is enabled, filename, line number and user message. Buffer size is limited by VS_IOT_LOGGER_MAX_BUFFER_SIZE define.
[in] | level | Message log level |
[in] | cur_filename | Source code file name. If NULL, there will be no filename information. |
[in] | line_num | Source code line number. If zero, there will be no line number. |
[in] | log_format | printf like string |
void vs_logger_message_hex | ( | vs_log_level_t | level, |
const char * | cur_filename, | ||
uint32_t | line_num, | ||
const char * | prefix, | ||
const void * | data_buf, | ||
const uint16_t | data_size | ||
) |
Log HEX buffer.
Sends BUF as hex string by calling vs_logger_message function.
[in] | level | Logging level |
[in] | cur_filename | Source code file name. If NULL, there will be no filename information. |
[in] | line_num | Source code line number. If zero, there will be no line number. |
[in] | prefix | Prefix for output. Must not be NULL. |
[in] | data_buf | Buffer to be output as HEX. Must not be NULL. |
[in] | SIZE | Size of the array to be output as HEX. Must not be zero. |
vs_log_level_t vs_logger_set_loglev | ( | vs_log_level_t | new_level | ) |
Set current logging level.
[in] | new_level | New logging level to be initialized |