Unify Framework Lib 1.6.0
sl_log.h
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
26#ifndef LOG_H
27#define LOG_H
28#include <stdio.h>
29#include "sl_status.h"
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
38typedef enum sl_log_level {
45
46// TODO: move array to string(hex) to utility function instead
48#define sl_log_byte_arr(tag, lvl, _arr, _arr_len) \
49 { \
50 char _tmp_log_arr[_arr_len * 2 + 1] = {0}; \
51 char *_cur_log_arr_idx = _tmp_log_arr; \
52 for (unsigned int _log_arr_count = 0; _log_arr_count < _arr_len; \
53 _log_arr_count++) { \
54 _cur_log_arr_idx \
55 += snprintf(_cur_log_arr_idx, \
56 sizeof(_tmp_log_arr) - (_cur_log_arr_idx - _tmp_log_arr), \
57 "%02X", \
58 (_arr)[_log_arr_count]); \
59 } \
60 sl_log(tag, lvl, "%s\n", _tmp_log_arr); \
61 }
62
63#ifdef ZWAVE_BUILD_SYSTEM
64
65#include "sl_log_gecko.h"
66
67#else
68
75
82
92void sl_log_set_tag_level(const char *tag, sl_log_level_t level);
93
102void sl_log_unset_tag_level(const char *tag);
103
117
122
131void sl_log(const char *const tag,
132 sl_log_level_t level,
133 const char *fmtstr,
134 ...);
135
136#define COLOR_START "\033[32;1m"
137#define COLOR_END "\033[0m"
138// Logging macros for calling sl_log with levels
139#define sl_log_debug(tag, fmtstr, ...) \
140 sl_log(tag, SL_LOG_DEBUG, fmtstr, ##__VA_ARGS__)
141#define sl_log_info(tag, fmtstr, ...) \
142 sl_log(tag, SL_LOG_INFO, fmtstr, ##__VA_ARGS__)
143#define sl_log_warning(tag, fmtstr, ...) \
144 sl_log(tag, SL_LOG_WARNING, fmtstr, ##__VA_ARGS__)
145#define sl_log_error(tag, fmtstr, ...) \
146 sl_log(tag, SL_LOG_ERROR, fmtstr, ##__VA_ARGS__)
147#define sl_log_critical(tag, fmtstr, ...) \
148 sl_log(tag, SL_LOG_CRITICAL, fmtstr, ##__VA_ARGS__)
149
150#endif // ZWAVE_BUILD_SYSTEM
151
152#ifdef __cplusplus
153}
154#endif
155
156#endif //LOG_H
sl_status_t sl_log_level_from_string(const char *level, sl_log_level_t *result)
Convert sl_log_level as string to sl_log_level_t.
sl_log_level_t sl_log_get_level()
Get log level.
void sl_log_unset_tag_level(const char *tag)
Remove tag specific log level for tag.
void sl_log_set_tag_level(const char *tag, sl_log_level_t level)
Set log level for a given tag.
void sl_log(const char *const tag, sl_log_level_t level, const char *fmtstr,...)
Write to the log.
void sl_log_read_config()
Read configuration from config library.
void sl_log_set_level(sl_log_level_t level)
Set log level.
enum sl_log_level sl_log_level_t
Log levels.
sl_log_level
Log levels.
Definition: sl_log.h:38
@ SL_LOG_ERROR
Definition: sl_log.h:42
@ SL_LOG_DEBUG
Definition: sl_log.h:39
@ SL_LOG_CRITICAL
Definition: sl_log.h:43
@ SL_LOG_WARNING
Definition: sl_log.h:41
@ SL_LOG_INFO
Definition: sl_log.h:40
uint32_t sl_status_t
Definition: sl_status.h:139
SL Status Codes.