Zephyr API Documentation
4.0.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 = COND_CODE_1(CONFIG_LOG_FMT_SECTION, \
332
(UTIL_CAT(_name, _str)), (STRINGIFY(_name))), \
333
.level = (_level) \
334
}
335
336
#define _LOG_MODULE_DYNAMIC_DATA_CREATE(_name) \
337
STRUCT_SECTION_ITERABLE_ALTERNATE(log_dynamic, log_source_dynamic_data, \
338
LOG_ITEM_DYNAMIC_DATA(_name))
339
340
#define _LOG_MODULE_DYNAMIC_DATA_COND_CREATE(_name) \
341
IF_ENABLED(CONFIG_LOG_RUNTIME_FILTERING, \
342
(_LOG_MODULE_DYNAMIC_DATA_CREATE(_name);))
343
344
#define _LOG_MODULE_DATA_CREATE(_name, _level) \
345
_LOG_MODULE_CONST_DATA_CREATE(_name, _level); \
346
_LOG_MODULE_DYNAMIC_DATA_COND_CREATE(_name)
347
348
/* Determine if data for the module shall be created. It is created if logging
349
* is enabled, override level is set or module specific level is set (not off).
350
*/
351
#define Z_DO_LOG_MODULE_REGISTER(...) \
352
COND_CODE_1(CONFIG_LOG, \
353
(Z_LOG_EVAL(CONFIG_LOG_OVERRIDE_LEVEL, \
354
(1), \
355
(Z_LOG_EVAL(_LOG_LEVEL_RESOLVE(__VA_ARGS__), (1), (0))) \
356
)), (0))
357
389
#define LOG_MODULE_REGISTER(...) \
390
COND_CODE_1( \
391
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__), \
392
(_LOG_MODULE_DATA_CREATE(GET_ARG_N(1, __VA_ARGS__), \
393
_LOG_LEVEL_RESOLVE(__VA_ARGS__))),\
394
() \
395
) \
396
LOG_MODULE_DECLARE(__VA_ARGS__)
397
424
#define LOG_MODULE_DECLARE(...) \
425
extern const struct log_source_const_data \
426
Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)); \
427
extern struct log_source_dynamic_data \
428
LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)); \
429
\
430
static const struct log_source_const_data * \
431
__log_current_const_data __unused = \
432
Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) ? \
433
&Z_LOG_ITEM_CONST_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
434
NULL; \
435
\
436
static struct log_source_dynamic_data * \
437
__log_current_dynamic_data __unused = \
438
(Z_DO_LOG_MODULE_REGISTER(__VA_ARGS__) && \
439
IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING)) ? \
440
&LOG_ITEM_DYNAMIC_DATA(GET_ARG_N(1, __VA_ARGS__)) : \
441
NULL; \
442
\
443
static const uint32_t __log_level __unused = \
444
_LOG_LEVEL_RESOLVE(__VA_ARGS__)
445
453
#define LOG_LEVEL_SET(level) static const uint32_t __log_level __unused = \
454
Z_LOG_RESOLVED_LEVEL(level, 0)
455
456
#ifdef CONFIG_LOG_CUSTOM_HEADER
457
/* This include must always be at the end of log.h */
458
#include <zephyr_custom_log.h>
459
#endif
460
461
/*
462
* Eclipse CDT or JetBrains Clion parser is sometimes confused by logging API
463
* code and freezes the whole IDE. Following lines hides LOG_x macros from them.
464
*/
465
#if defined(__CDT_PARSER__) || defined(__JETBRAINS_IDE__)
466
#undef LOG_ERR
467
#undef LOG_WRN
468
#undef LOG_INF
469
#undef LOG_DBG
470
471
#undef LOG_HEXDUMP_ERR
472
#undef LOG_HEXDUMP_WRN
473
#undef LOG_HEXDUMP_INF
474
#undef LOG_HEXDUMP_DBG
475
476
#define LOG_ERR(...) (void) 0
477
#define LOG_WRN(...) (void) 0
478
#define LOG_DBG(...) (void) 0
479
#define LOG_INF(...) (void) 0
480
481
#define LOG_HEXDUMP_ERR(...) (void) 0
482
#define LOG_HEXDUMP_WRN(...) (void) 0
483
#define LOG_HEXDUMP_DBG(...) (void) 0
484
#define LOG_HEXDUMP_INF(...) (void) 0
485
#endif
486
491
#endif
/* ZEPHYR_INCLUDE_LOGGING_LOG_H_ */
log_core.h
log_instance.h
iterable_sections.h
zephyr
logging
log.h
Generated on Sat Nov 16 2024 04:55:03 for Zephyr API Documentation by
1.12.0