|
Kaa client C SDK
|
Simple logger for Kaa C Endpoint. More...
#include "kaa_error.h"#include <platform/defaults.h>#include <platform/stdio.h>#include <stdint.h>Go to the source code of this file.
Macros | |
| #define | KAA_LOG_LEVEL_NONE 0 |
| Use as the max log level to switch logging off. More... | |
| #define | KAA_LOG_LEVEL_FATAL 1 |
| Use for severe errors that cause premature program termination. More... | |
| #define | KAA_LOG_LEVEL_ERROR 2 |
| Use for runtime errors or unexpected conditions that the program might gracefully recover from. More... | |
| #define | KAA_LOG_LEVEL_WARN 3 |
| Use for unexpected or undesirable runtime conditions that are not necessarily affecting the program. More... | |
| #define | KAA_LOG_LEVEL_INFO 4 |
| Use for important or interesting runtime events that help understanding what the program is doing. More... | |
| #define | KAA_LOG_LEVEL_DEBUG 5 |
| Use to log detailed information on the logic flow through the system. More... | |
| #define | KAA_LOG_LEVEL_TRACE 6 |
| Use to log most detailed information intended for development and debugging purposes only. More... | |
| #define | KAA_MAX_LOG_LEVEL KAA_LOG_LEVEL_TRACE |
| Use KAA_LOG_TRACE as the max log level by default. More... | |
| #define | KAA_LOG_LEVEL_FATAL_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_FATAL) |
| #define | KAA_LOG_LEVEL_ERROR_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_ERROR) |
| #define | KAA_LOG_LEVEL_WARN_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_WARN) |
| #define | KAA_LOG_LEVEL_INFO_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_INFO) |
| #define | KAA_LOG_LEVEL_DEBUG_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_DEBUG) |
| #define | KAA_LOG_LEVEL_TRACE_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_TRACE) |
| #define | KAA_LOG_FATAL(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_FATAL, err, __VA_ARGS__) |
| #define | KAA_LOG_ERROR(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_ERROR, err, __VA_ARGS__) |
| #define | KAA_LOG_WARN(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_WARN, err, __VA_ARGS__) |
| #define | KAA_LOG_INFO(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_INFO, err, __VA_ARGS__) |
| #define | KAA_LOG_DEBUG(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_DEBUG, err, __VA_ARGS__) |
| #define | KAA_LOG_TRACE(logger, err,...) kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_TRACE, err, __VA_ARGS__) |
| #define | KAA_LOG_TRACE_LDB(logger, err,...) do { (void)(logger); (void)(err); } while (0) |
Typedefs | |
| typedef struct kaa_logger_t | kaa_logger_t |
| typedef uint8_t | kaa_log_level_t |
| Log level type. More... | |
Functions | |
| kaa_error_t | kaa_log_create (kaa_logger_t **logger, size_t buffer_size, kaa_log_level_t max_log_level, FILE *sink) |
| Creates and initializes a logger instance. More... | |
| kaa_error_t | kaa_log_destroy (kaa_logger_t *logger) |
| Deinitializes and destroys the logger instance. More... | |
| kaa_log_level_t | kaa_get_max_log_level (const kaa_logger_t *self) |
| Retrieves the current log level. More... | |
| kaa_error_t | kaa_set_max_log_level (kaa_logger_t *self, kaa_log_level_t max_log_level) |
| Sets the maximum log level. More... | |
| kaa_error_t | kaa_log_set_sink (kaa_logger_t *self, FILE *sink) |
| Sets user sink for log output. More... | |
| void | kaa_log_write (kaa_logger_t *self, const char *source_file, int lineno, kaa_log_level_t log_level, kaa_error_t error_code, const char *format,...) |
| Compiles a log message and puts it into the sink. More... | |
Simple logger for Kaa C Endpoint.
Supports runtime limitation of the maximum log level to be logged. Expects externally provided and managed valid FILE* reference to log data to. Not thread safe.
| #define KAA_LOG_DEBUG | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_DEBUG, err, __VA_ARGS__) |
| #define KAA_LOG_ERROR | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_ERROR, err, __VA_ARGS__) |
| #define KAA_LOG_FATAL | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_FATAL, err, __VA_ARGS__) |
| #define KAA_LOG_INFO | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_INFO, err, __VA_ARGS__) |
| #define KAA_LOG_LEVEL_DEBUG 5 |
Use to log detailed information on the logic flow through the system.
| #define KAA_LOG_LEVEL_DEBUG_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_DEBUG) |
| #define KAA_LOG_LEVEL_ERROR 2 |
Use for runtime errors or unexpected conditions that the program might gracefully recover from.
| #define KAA_LOG_LEVEL_ERROR_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_ERROR) |
| #define KAA_LOG_LEVEL_FATAL 1 |
Use for severe errors that cause premature program termination.
| #define KAA_LOG_LEVEL_FATAL_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_FATAL) |
| #define KAA_LOG_LEVEL_INFO 4 |
Use for important or interesting runtime events that help understanding what the program is doing.
| #define KAA_LOG_LEVEL_INFO_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_INFO) |
| #define KAA_LOG_LEVEL_NONE 0 |
Use as the max log level to switch logging off.
| #define KAA_LOG_LEVEL_TRACE 6 |
Use to log most detailed information intended for development and debugging purposes only.
| #define KAA_LOG_LEVEL_TRACE_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_TRACE) |
| #define KAA_LOG_LEVEL_WARN 3 |
Use for unexpected or undesirable runtime conditions that are not necessarily affecting the program.
| #define KAA_LOG_LEVEL_WARN_ENABLED (KAA_MAX_LOG_LEVEL >= KAA_LOG_LEVEL_WARN) |
| #define KAA_LOG_TRACE | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_TRACE, err, __VA_ARGS__) |
| #define KAA_LOG_TRACE_LDB | ( | logger, | |
| err, | |||
| ... | |||
| ) | do { (void)(logger); (void)(err); } while (0) |
| #define KAA_LOG_WARN | ( | logger, | |
| err, | |||
| ... | |||
| ) | kaa_log_write(logger, __FILE__, __LINE__, KAA_LOG_LEVEL_WARN, err, __VA_ARGS__) |
| #define KAA_MAX_LOG_LEVEL KAA_LOG_LEVEL_TRACE |
Use KAA_LOG_TRACE as the max log level by default.
| typedef uint8_t kaa_log_level_t |
Log level type.
| typedef struct kaa_logger_t kaa_logger_t |
| kaa_log_level_t kaa_get_max_log_level | ( | const kaa_logger_t * | self | ) |
Retrieves the current log level.
| [in] | self | Pointer to a logger. |
| KAA_LOG_LEVEL_NONE | self is NULL. |
| kaa_error_t kaa_log_create | ( | kaa_logger_t ** | logger, |
| size_t | buffer_size, | ||
| kaa_log_level_t | max_log_level, | ||
| FILE * | sink | ||
| ) |
Creates and initializes a logger instance.
| [in,out] | logger | Address of a pointer to the newly created logger. |
| [in] | buffer_size | Size of the log message buffer to allocate to the logger. |
| [in] | max_log_level | Max log level to be used. Use KAA_LOG_LEVEL_NONE to switch the logger off. |
| [in] | sink | Valid, opened file to write logs to. Will use stdout if NULL is provided. |
| kaa_error_t kaa_log_destroy | ( | kaa_logger_t * | logger | ) |
Deinitializes and destroys the logger instance.
| [in,out] | logger | Pointer to a logger. |
| kaa_error_t kaa_log_set_sink | ( | kaa_logger_t * | self, |
| FILE * | sink | ||
| ) |
Sets user sink for log output.
| [in] | self | Pointer to a logger. |
| [in] | sink | Pointer to FILE structure where logs will be written to. |
| void kaa_log_write | ( | kaa_logger_t * | self, |
| const char * | source_file, | ||
| int | lineno, | ||
| kaa_log_level_t | log_level, | ||
| kaa_error_t | error_code, | ||
| const char * | format, | ||
| ... | |||
| ) |
Compiles a log message and puts it into the sink.
The message format is as follows:
NOTE: Do not use directly. Use one of KAA_LOG_FATAL, KAA_LOG_ERROR, KAA_LOG_WARN, KAA_LOG_INFO, KAA_LOG_DEBUG, KAA_LOG_TRACE macros instead.
The log message gets truncated if it is longer than buffer_size specified to kaa_log_create.
| [in] | self | Pointer to a logger. |
| [in] | source_file | The source file that the message is logged from. |
| [in] | lineno | The line number in the source file that the message is logged from. |
| [in] | log_level | The message log level to log with. |
| [in] | error_code | The message error code. |
| [in] | format | The format of the message to log. |
| kaa_error_t kaa_set_max_log_level | ( | kaa_logger_t * | self, |
| kaa_log_level_t | max_log_level | ||
| ) |
Sets the maximum log level.
| [in] | self | Pointer to a logger. |
| [in] | max_log_level | Max log level to be used. Use KAA_LOG_LEVEL_NONE to switch the logger off. |
1.8.6