Zephyr Project API
3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2018 Nordic Semiconductor ASA
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef ZEPHYR_INCLUDE_LOGGING_LOG_H_
8
#define ZEPHYR_INCLUDE_LOGGING_LOG_H_
9
10
#include <
zephyr/logging/log_instance.h
>
11
#include <
zephyr/logging/log_core.h
>
12
#include <
zephyr/sys/iterable_sections.h
>
13
14
#ifdef __cplusplus
15
extern
"C"
{
16
#endif
17
44
#define LOG_ERR(...) Z_LOG(LOG_LEVEL_ERR, __VA_ARGS__)
45
55
#define LOG_WRN(...) Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__)
56
65
#define LOG_INF(...) Z_LOG(LOG_LEVEL_INF, __VA_ARGS__)
66
75
#define LOG_DBG(...) Z_LOG(LOG_LEVEL_DBG, __VA_ARGS__)
76
86
#define LOG_WRN_ONCE(...) \
87
do { \
88
static uint8_t __warned; \
89
if (unlikely(__warned == 0)) { \
90
Z_LOG(LOG_LEVEL_WRN, __VA_ARGS__); \
91
__warned = 1; \
92
} \
93
} while (0)
94
104
#define LOG_PRINTK(...) Z_LOG_PRINTK(0, __VA_ARGS__)
105
114
#define LOG_RAW(...) Z_LOG_PRINTK(1, __VA_ARGS__)
115
128
#define LOG_INST_ERR(_log_inst, ...) \
129
Z_LOG_INSTANCE(LOG_LEVEL_ERR, _log_inst, __VA_ARGS__)
130
144
#define LOG_INST_WRN(_log_inst, ...) \
145
Z_LOG_INSTANCE(LOG_LEVEL_WRN, _log_inst, __VA_ARGS__)
146
159
#define LOG_INST_INF(_log_inst, ...) \
160
Z_LOG_INSTANCE(LOG_LEVEL_INF, _log_inst, __VA_ARGS__)
161
174
#define LOG_INST_DBG(_log_inst, ...) \
175
Z_LOG_INSTANCE(LOG_LEVEL_DBG, _log_inst, __VA_ARGS__)
176
187
#define LOG_HEXDUMP_ERR(_data, _length, _str) \
188
Z_LOG_HEXDUMP(LOG_LEVEL_ERR, _data, _length, (_str))
189
200
#define LOG_HEXDUMP_WRN(_data, _length, _str) \
201
Z_LOG_HEXDUMP(LOG_LEVEL_WRN, _data, _length, (_str))
202
212
#define LOG_HEXDUMP_INF(_data, _length, _str) \
213
Z_LOG_HEXDUMP(LOG_LEVEL_INF, _data, _length, (_str))
214
224
#define LOG_HEXDUMP_DBG(_data, _length, _str) \
225
Z_LOG_HEXDUMP(LOG_LEVEL_DBG, _data, _length, (_str))
226
241
#define LOG_INST_HEXDUMP_ERR(_log_inst, _data, _length, _str) \
242
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_ERR, _log_inst, _data, _length, _str)
243
256
#define LOG_INST_HEXDUMP_WRN(_log_inst, _data, _length, _str) \
257
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_WRN, _log_inst, _data, _length, _str)
258
270
#define LOG_INST_HEXDUMP_INF(_log_inst, _data, _length, _str) \
271
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_INF, _log_inst, _data, _length, _str)
272
284
#define LOG_INST_HEXDUMP_DBG(_log_inst, _data, _length, _str) \
285
Z_LOG_HEXDUMP_INSTANCE(LOG_LEVEL_DBG, _log_inst, _data, _length, _str)
286
299
void
z_log_vprintk(
const
char
*fmt, va_list ap);
300
301
#ifdef __cplusplus
302
}
303
#define LOG_IN_CPLUSPLUS 1
304
#endif
305
/* Macro expects that optionally on second argument local log level is provided.
306
* If provided it is returned, otherwise default log level is returned or
307
* LOG_LEVEL, if it was locally defined.
308
*/
309
#if !defined(CONFIG_LOG)
310
#define _LOG_LEVEL_RESOLVE(...) LOG_LEVEL_NONE
311
#else
312
#define _LOG_LEVEL_RESOLVE(...) \
313
Z_LOG_EVAL(COND_CODE_0(LOG_LEVEL, (1), (LOG_LEVEL)), \
314
(GET_ARG_N(2, __VA_ARGS__, LOG_LEVEL)), \
315
(GET_ARG_N(2, __VA_ARGS__, CONFIG_LOG_DEFAULT_LEVEL)))
316
#endif
317
318
/* Return first argument */
319
#define _LOG_ARG1(arg1, ...) arg1
320
321
#define _LOG_MODULE_CONST_DATA_CREATE(_name, _level) \
322
IF_ENABLED(CONFIG_LOG_FMT_SECTION, ( \
323
static const char UTIL_CAT(_name, _str)[] \
324
__in_section(_log_strings, static, _CONCAT(_name, _)) __used __noasan = \
325
STRINGIFY(_name);)) \
326
IF_ENABLED(LOG_IN_CPLUSPLUS, (extern)) \
327
const STRUCT_SECTION_ITERABLE_ALTERNATE(log_const, \
328
log_source_const_data, \
329
Z_LOG_ITEM_CONST_DATA(_name)) = \
330
{ \
331
.name = IS_ENABLED(CONFIG_LOG_FMT_SECTION_STRIP) ? NULL : \
332
COND_CODE_1(CONFIG_LOG_FMT_SECTION, \
333
(UTIL_CAT(_name, _str)), (STRINGIFY(_name))), \
334
.level = (_level) \
335
}
336
337
#define _LOG_MODULE_DYNAMIC_DATA_CREATE(_name) \
338
STRUCT_SECTION_ITERABLE_ALTERNATE(log_dynamic, log_source_dynamic_data, \
339
LOG_ITEM_DYNAMIC_DATA(_name))
340
341
#define _LOG_MODULE_DYNAMIC_DATA_COND_CREATE(_name) \
342
IF_ENABLED(CONFIG_LOG_RUNTIME_FILTERING, \
343
(_LOG_MODULE_DYNAMIC_DATA_CREATE(_name);))
344
345
#define _LOG_MODULE_DATA_CREATE(_name, _level) \
346
_LOG_MODULE_CONST_DATA_CREATE(_name, _level); \
347
_LOG_MODULE_DYNAMIC_DATA_COND_CREATE(_name)
348
349
/* Determine if data for the module shall be created. It is created if logging
350
* is enabled, override level is set or module specific level is set (not off).
351
*/
352
#define Z_DO_LOG_MODULE_REGISTER(...) \
353
COND_CODE_1(CONFIG_LOG, \
354
(Z_LOG_EVAL(CONFIG_LOG_OVERRIDE_LEVEL, \
355
(1), \
356
(Z_LOG_EVAL(_LOG_LEVEL_RESOLVE(__VA_ARGS__), (1), (0))) \
357
)), (0))
358
390
#define LOG_MODULE_REGISTER(...) \
391
COND_CODE_1( \
392
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__), \
393
(_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__), \
394
_LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
395
() \
396
) \
397
LOG_MODULE_DECLARE(__VA_ARGS__)
398
425
#define LOG_MODULE_DECLARE(...) \
426
extern const struct log_source_const_data \
427
Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)); \
428
extern struct log_source_dynamic_data \
429
LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)); \
430
\
431
static const struct log_source_const_data * \
432
__log_current_const_data __unused = \
433
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) ? \
434
&Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
435
NULL; \
436
\
437
static struct log_source_dynamic_data * \
438
__log_current_dynamic_data __unused = \
439
(Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) && \
440
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \
441
&LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
442
NULL; \
443
\
444
static const uint32_t __log_level __unused = \
445
_LOG_LEVEL_RESOLVE(__VA_ARGS__)
446
454
#define LOG_LEVEL_SET(level) static const uint32_t __log_level __unused = \
455
Z_LOG_RESOLVED_LEVEL(level, 0)
456
457
#ifdef CONFIG_LOG_CUSTOM_HEADER
458
/* This include must always be at the end of log.h */
459
#include <zephyr_custom_log.h>
460
#endif
461
462
/*
463
* Eclipse CDT or JetBrains Clion parser is sometimes confused by logging API
464
* code and freezes the whole IDE. Following lines hides LOG_x macros from them.
465
*/
466
#if defined(__CDT_PARSER__) || defined(__JETBRAINS_IDE__)
467
#undef LOG_ERR
468
#undef LOG_WRN
469
#undef LOG_INF
470
#undef LOG_DBG
471
472
#undef LOG_HEXDUMP_ERR
473
#undef LOG_HEXDUMP_WRN
474
#undef LOG_HEXDUMP_INF
475
#undef LOG_HEXDUMP_DBG
476
477
#define LOG_ERR(...) (void) 0
478
#define LOG_WRN(...) (void) 0
479
#define LOG_DBG(...) (void) 0
480
#define LOG_INF(...) (void) 0
481
482
#define LOG_HEXDUMP_ERR(...) (void) 0
483
#define LOG_HEXDUMP_WRN(...) (void) 0
484
#define LOG_HEXDUMP_DBG(...) (void) 0
485
#define LOG_HEXDUMP_INF(...) (void) 0
486
#endif
487
492
#endif
/* ZEPHYR_INCLUDE_LOGGING_LOG_H_ */
log_core.h
log_instance.h
iterable_sections.h
include
zephyr
logging
log.h
Generated on Sun Sep 15 2024 17:01:30 for Zephyr Project API by
1.9.8