supla-device
Loading...
Searching...
No Matches
log_wrapper.h
1/*
2 * Copyright (C) AC SOFTWARE SP. Z O.O
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef SRC_SUPLA_LOG_WRAPPER_H_
20#define SRC_SUPLA_LOG_WRAPPER_H_
21
22#include <stdarg.h>
23
24#include <supla-common/log.h>
25
26// add declaration of methods defined in log.c, but not exposed to log.h
27extern "C" char supla_log_string(char **buffer, int *size, va_list va,
28 const char *__fmt);
29extern "C" void supla_vlog(int __pri, const char *message);
30
31#define PRINTF_UINT64_HEX(x) \
32 static_cast<uint32_t>((x) >> 32), static_cast<uint32_t>(x)
33
34#ifdef ARDUINO
35#include <Arduino.h>
36
37class __FlashStringHelper;
38
39void supla_logf(int __pri, const __FlashStringHelper *__fmt, ...);
40
41#else
42
43#ifndef F
44#define F(argument_F) (argument_F)
45#endif
46
47#define supla_logf supla_log
48#endif
49
50// #define SUPLA_DISABLE_LOGS
51
52#ifdef SUPLA_DISABLE_LOGS
53// uncomment below lines to disable certain logs
54#define SUPLA_LOG_VERBOSE(arg_format, ...) {};
55#define SUPLA_LOG_DEBUG(arg_format, ...) {};
56#define SUPLA_LOG_INFO(arg_format, ...) {};
57#define SUPLA_LOG_WARNING(arg_format, ...) {};
58#define SUPLA_LOG_ERROR(arg_format, ...) {};
59#endif
60
61#ifdef SUPLA_DEVICE_ESP32
62#include <esp_log.h>
63extern const char *SUPLA_TAG;
64#ifndef SUPLA_LOG_VERBOSE
65#define SUPLA_LOG_VERBOSE(arg_format, ...) \
66 ESP_LOGV(SUPLA_TAG, arg_format, ## __VA_ARGS__)
67#endif
68
69#ifndef SUPLA_LOG_DEBUG
70#define SUPLA_LOG_DEBUG(arg_format, ...) \
71 ESP_LOGD(SUPLA_TAG, arg_format, ## __VA_ARGS__)
72#endif
73
74#ifndef SUPLA_LOG_INFO
75#define SUPLA_LOG_INFO(arg_format, ...) \
76 ESP_LOGI(SUPLA_TAG, arg_format, ## __VA_ARGS__)
77#endif
78
79#ifndef SUPLA_LOG_WARNING
80#define SUPLA_LOG_WARNING(arg_format, ...) \
81 ESP_LOGW(SUPLA_TAG, arg_format, ## __VA_ARGS__)
82#endif
83
84#ifndef SUPLA_LOG_ERROR
85#define SUPLA_LOG_ERROR(arg_format, ...) \
86 ESP_LOGE(SUPLA_TAG, arg_format, ## __VA_ARGS__)
87#endif
88
89#endif
90
91#ifndef SUPLA_LOG_VERBOSE
92#define SUPLA_LOG_VERBOSE(arg_format, ...) \
93 supla_logf(LOG_VERBOSE, F(arg_format) , ## __VA_ARGS__)
94#endif
95
96#ifndef SUPLA_LOG_DEBUG
97#define SUPLA_LOG_DEBUG(arg_format, ...) \
98 supla_logf(LOG_DEBUG, F(arg_format) , ## __VA_ARGS__)
99#endif
100
101#ifndef SUPLA_LOG_INFO
102#define SUPLA_LOG_INFO(arg_format, ...) \
103 supla_logf(LOG_INFO, F(arg_format) , ## __VA_ARGS__)
104#endif
105
106#ifndef SUPLA_LOG_WARNING
107#define SUPLA_LOG_WARNING(arg_format, ...) \
108 supla_logf(LOG_WARNING, F(arg_format) , ## __VA_ARGS__)
109#endif
110
111#ifndef SUPLA_LOG_ERROR
112#define SUPLA_LOG_ERROR(arg_format, ...) \
113 supla_logf(LOG_ERR, F(arg_format) , ## __VA_ARGS__)
114#endif
115
116#endif // SRC_SUPLA_LOG_WRAPPER_H_