supla-device
Loading...
Searching...
No Matches
log_wrapper.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_LOG_WRAPPER_H_
5#define SRC_SUPLA_LOG_WRAPPER_H_
6
7#include <stdarg.h>
8
9#include <supla-common/log.h>
10
11// add declaration of methods defined in log.c, but not exposed to log.h
12extern "C" char supla_log_string(char **buffer, int *size, va_list va,
13 const char *__fmt);
14extern "C" void supla_vlog(int __pri, const char *message);
15
16#define PRINTF_UINT64_HEX(x) \
17 static_cast<uint32_t>((x) >> 32), static_cast<uint32_t>(x)
18
19#define SUPLA_LOG_IS_ENABLED(level) supla_log_is_enabled(level)
20
21#ifdef ARDUINO
22#include <Arduino.h>
23
24class __FlashStringHelper;
25
26void supla_logf(int __pri, const __FlashStringHelper *__fmt, ...);
27
28#else
29
30#ifndef F
31#define F(argument_F) (argument_F)
32#endif
33
34#define supla_logf supla_log
35#endif
36
37// #define SUPLA_DISABLE_LOGS
38
39#ifdef SUPLA_DISABLE_LOGS
40// uncomment below lines to disable certain logs
41#define SUPLA_LOG_VERBOSE(arg_format, ...) {};
42#define SUPLA_LOG_DEBUG(arg_format, ...) {};
43#define SUPLA_LOG_INFO(arg_format, ...) {};
44#define SUPLA_LOG_WARNING(arg_format, ...) {};
45#define SUPLA_LOG_ERROR(arg_format, ...) {};
46#endif
47
48#ifdef SUPLA_DEVICE_ESP32
49#include <esp_log.h>
50extern const char *SUPLA_TAG;
51void supla_device_logf(int __pri, const char *__fmt, ...);
52#ifndef SUPLA_LOG_VERBOSE
53#define SUPLA_LOG_VERBOSE(arg_format, ...) \
54 do { \
55 if (SUPLA_LOG_IS_ENABLED(LOG_VERBOSE)) { \
56 supla_device_logf(LOG_VERBOSE, arg_format, ## __VA_ARGS__); \
57 } \
58 } while (0)
59#endif
60
61#ifndef SUPLA_LOG_DEBUG
62#define SUPLA_LOG_DEBUG(arg_format, ...) \
63 do { \
64 if (SUPLA_LOG_IS_ENABLED(LOG_DEBUG)) { \
65 supla_device_logf(LOG_DEBUG, arg_format, ## __VA_ARGS__); \
66 } \
67 } while (0)
68#endif
69
70#ifndef SUPLA_LOG_INFO
71#define SUPLA_LOG_INFO(arg_format, ...) \
72 do { \
73 if (SUPLA_LOG_IS_ENABLED(LOG_INFO)) { \
74 supla_device_logf(LOG_INFO, arg_format, ## __VA_ARGS__); \
75 } \
76 } while (0)
77#endif
78
79#ifndef SUPLA_LOG_WARNING
80#define SUPLA_LOG_WARNING(arg_format, ...) \
81 do { \
82 if (SUPLA_LOG_IS_ENABLED(LOG_WARNING)) { \
83 supla_device_logf(LOG_WARNING, arg_format, ## __VA_ARGS__); \
84 } \
85 } while (0)
86#endif
87
88#ifndef SUPLA_LOG_ERROR
89#define SUPLA_LOG_ERROR(arg_format, ...) \
90 do { \
91 if (SUPLA_LOG_IS_ENABLED(LOG_ERR)) { \
92 supla_device_logf(LOG_ERR, arg_format, ## __VA_ARGS__); \
93 } \
94 } while (0)
95#endif
96
97#endif
98
99#ifndef SUPLA_LOG_VERBOSE
100#define SUPLA_LOG_VERBOSE(arg_format, ...) \
101 do { \
102 if (SUPLA_LOG_IS_ENABLED(LOG_VERBOSE)) { \
103 supla_logf(LOG_VERBOSE, F(arg_format) , ## __VA_ARGS__); \
104 } \
105 } while (0)
106#endif
107
108#ifndef SUPLA_LOG_DEBUG
109#define SUPLA_LOG_DEBUG(arg_format, ...) \
110 do { \
111 if (SUPLA_LOG_IS_ENABLED(LOG_DEBUG)) { \
112 supla_logf(LOG_DEBUG, F(arg_format) , ## __VA_ARGS__); \
113 } \
114 } while (0)
115#endif
116
117#ifndef SUPLA_LOG_INFO
118#define SUPLA_LOG_INFO(arg_format, ...) \
119 do { \
120 if (SUPLA_LOG_IS_ENABLED(LOG_INFO)) { \
121 supla_logf(LOG_INFO, F(arg_format) , ## __VA_ARGS__); \
122 } \
123 } while (0)
124#endif
125
126#ifndef SUPLA_LOG_WARNING
127#define SUPLA_LOG_WARNING(arg_format, ...) \
128 do { \
129 if (SUPLA_LOG_IS_ENABLED(LOG_WARNING)) { \
130 supla_logf(LOG_WARNING, F(arg_format) , ## __VA_ARGS__); \
131 } \
132 } while (0)
133#endif
134
135#ifndef SUPLA_LOG_ERROR
136#define SUPLA_LOG_ERROR(arg_format, ...) \
137 do { \
138 if (SUPLA_LOG_IS_ENABLED(LOG_ERR)) { \
139 supla_logf(LOG_ERR, F(arg_format) , ## __VA_ARGS__); \
140 } \
141 } while (0)
142#endif
143
144#endif // SRC_SUPLA_LOG_WRAPPER_H_