NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
NimBLELog.h
1/*
2 * Copyright 2020-2024 Ryan Powell <ryan@nable-embedded.io> and
3 * esp-nimble-cpp, NimBLE-Arduino contributors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NIMBLE_CPP_LOG_H_
19#define NIMBLE_CPP_LOG_H_
20
21#include "nimconfig.h"
22#if defined(CONFIG_BT_ENABLED)
23
24# if defined(CONFIG_NIMBLE_CPP_IDF)
25# include "esp_log.h"
26# include "console/console.h"
27# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
28# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
29# endif
30
31# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
32 do { \
33 if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
34 } while (0)
35
36# define NIMBLE_LOGD(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_DEBUG, tag, format, ##__VA_ARGS__)
37# define NIMBLE_LOGI(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_INFO, tag, format, ##__VA_ARGS__)
38# define NIMBLE_LOGW(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_WARN, tag, format, ##__VA_ARGS__)
39# define NIMBLE_LOGE(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
40
41# else
42# include "nimble/porting/nimble/include/syscfg/syscfg.h"
43# include "nimble/console/console.h"
44# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
45# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
46# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
47# else
48# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
49# endif
50# endif
51
52# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
53# define NIMBLE_LOGD(tag, format, ...) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
54# else
55# define NIMBLE_LOGD(tag, format, ...) (void)tag
56# endif
57
58# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
59# define NIMBLE_LOGI(tag, format, ...) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
60# else
61# define NIMBLE_LOGI(tag, format, ...) (void)tag
62# endif
63
64# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
65# define NIMBLE_LOGW(tag, format, ...) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
66# else
67# define NIMBLE_LOGW(tag, format, ...) (void)tag
68# endif
69
70# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
71# define NIMBLE_LOGE(tag, format, ...) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
72# else
73# define NIMBLE_LOGE(tag, format, ...) (void)tag
74# endif
75
76# endif /* CONFIG_NIMBLE_CPP_IDF */
77#endif /* CONFIG_BT_ENABLED */
78#endif /* NIMBLE_CPP_LOG_H_ */