Line data Source code
1 0 : /*
2 : * Copyright (c) 2018 Nordic Semiconductor ASA
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 : #ifndef ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_
7 : #define ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_
8 :
9 : #include <zephyr/logging/log_msg.h>
10 : #include <zephyr/logging/log_instance.h>
11 : #include <stdbool.h>
12 : #include <stdint.h>
13 : #include <stdarg.h>
14 : #include <zephyr/sys/util.h>
15 :
16 : /* This header file keeps all macros and functions needed for creating logging
17 : * messages (macros like @ref LOG_ERR).
18 : */
19 0 : #define LOG_LEVEL_NONE 0
20 0 : #define LOG_LEVEL_ERR 1
21 0 : #define LOG_LEVEL_WRN 2
22 0 : #define LOG_LEVEL_INF 3
23 0 : #define LOG_LEVEL_DBG 4
24 :
25 : #ifdef __cplusplus
26 : extern "C" {
27 : #endif
28 :
29 : #ifndef CONFIG_LOG
30 0 : #define CONFIG_LOG_DEFAULT_LEVEL 0
31 0 : #define CONFIG_LOG_MAX_LEVEL 0
32 : #endif
33 :
34 : /* Id of local domain. */
35 : #define Z_LOG_LOCAL_DOMAIN_ID 0
36 :
37 0 : #define LOG_FUNCTION_PREFIX_MASK \
38 : (((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_ERR) << \
39 : LOG_LEVEL_ERR) | \
40 : ((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_WRN) << \
41 : LOG_LEVEL_WRN) | \
42 : ((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_INF) << \
43 : LOG_LEVEL_INF) | \
44 : ((uint32_t)IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_DBG) << LOG_LEVEL_DBG))
45 :
46 : /** @brief Macro for returning local level value if defined or default.
47 : *
48 : * Check @ref IS_ENABLED macro for detailed explanation of the trick.
49 : */
50 : #define Z_LOG_RESOLVED_LEVEL(_level, _default) \
51 : Z_LOG_RESOLVED_LEVEL1(_level, _default)
52 :
53 : #define Z_LOG_RESOLVED_LEVEL1(_level, _default) \
54 : __COND_CODE(_LOG_XXXX##_level, (_level), (_default))
55 :
56 : #define _LOG_XXXX0 _LOG_YYYY,
57 : #define _LOG_XXXX1 _LOG_YYYY,
58 : #define _LOG_XXXX2 _LOG_YYYY,
59 : #define _LOG_XXXX3 _LOG_YYYY,
60 : #define _LOG_XXXX4 _LOG_YYYY,
61 :
62 : /**
63 : * @brief Macro for conditional code generation if provided log level allows.
64 : *
65 : * Macro behaves similarly to standard \#if \#else \#endif clause. The
66 : * difference is that it is evaluated when used and not when header file is
67 : * included.
68 : *
69 : * @param _eval_level Evaluated level. If level evaluates to one of existing log
70 : * log level (1-4) then macro evaluates to _iftrue.
71 : * @param _iftrue Code that should be inserted when evaluated to true. Note,
72 : * that parameter must be provided in brackets.
73 : * @param _iffalse Code that should be inserted when evaluated to false.
74 : * Note, that parameter must be provided in brackets.
75 : */
76 : #define Z_LOG_EVAL(_eval_level, _iftrue, _iffalse) \
77 : Z_LOG_EVAL1(_eval_level, _iftrue, _iffalse)
78 :
79 : #define Z_LOG_EVAL1(_eval_level, _iftrue, _iffalse) \
80 : __COND_CODE(_LOG_ZZZZ##_eval_level, _iftrue, _iffalse)
81 :
82 : #define _LOG_ZZZZ1 _LOG_YYYY,
83 : #define _LOG_ZZZZ2 _LOG_YYYY,
84 : #define _LOG_ZZZZ3 _LOG_YYYY,
85 : #define _LOG_ZZZZ4 _LOG_YYYY,
86 :
87 : /**
88 : *
89 : * @brief Macro for getting ID of current module.
90 : */
91 1 : #define LOG_CURRENT_MODULE_ID() (__log_level != 0 ? \
92 : log_const_source_id(__log_current_const_data) : 0U)
93 :
94 : /* Set of defines that are set to 1 if function name prefix is enabled for given level. */
95 : #define Z_LOG_FUNC_PREFIX_0 0
96 : #define Z_LOG_FUNC_PREFIX_1 COND_CODE_1(CONFIG_LOG_FUNC_NAME_PREFIX_ERR, (1), (0))
97 : #define Z_LOG_FUNC_PREFIX_2 COND_CODE_1(CONFIG_LOG_FUNC_NAME_PREFIX_WRN, (1), (0))
98 : #define Z_LOG_FUNC_PREFIX_3 COND_CODE_1(CONFIG_LOG_FUNC_NAME_PREFIX_INF, (1), (0))
99 : #define Z_LOG_FUNC_PREFIX_4 COND_CODE_1(CONFIG_LOG_FUNC_NAME_PREFIX_DBG, (1), (0))
100 :
101 : /**
102 : * @brief Macro for optional injection of function name as first argument of
103 : * formatted string. COND_CODE_0() macro is used to handle no arguments
104 : * case.
105 : *
106 : * The purpose of this macro is to prefix string literal with format specifier
107 : * for function name and inject function name as first argument. In order to
108 : * handle string with no arguments _LOG_Z_EVAL is used.
109 : */
110 : #define Z_LOG_STR_WITH_PREFIX2(...) \
111 : "%s: " GET_ARG_N(1, __VA_ARGS__), (const char *)__func__\
112 : COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__),\
113 : (),\
114 : (, GET_ARGS_LESS_N(1, __VA_ARGS__))\
115 : )
116 :
117 : /* Macro handles case when no format string is provided: e.g. LOG_DBG().
118 : * Handling of format string is deferred to the next level macro.
119 : */
120 : #define Z_LOG_STR_WITH_PREFIX(...) \
121 : COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
122 : ("%s", (const char *)__func__), \
123 : (Z_LOG_STR_WITH_PREFIX2(__VA_ARGS__)))
124 :
125 : /**
126 : * @brief Handle optional injection of function name as the first argument.
127 : *
128 : * Additionally, macro is handling the empty message case.
129 : */
130 : #define Z_LOG_STR(_level, ...) \
131 : COND_CODE_1(UTIL_CAT(Z_LOG_FUNC_PREFIX_##_level), \
132 : (Z_LOG_STR_WITH_PREFIX(__VA_ARGS__)), (__VA_ARGS__))
133 :
134 : #define Z_LOG_LEVEL_CHECK(_level, _check_level, _default_level) \
135 : ((_level) <= Z_LOG_RESOLVED_LEVEL(_check_level, _default_level))
136 :
137 : /** @brief Compile time level checking.
138 : *
139 : * This check is resolved at compile time and logging message is removed if check fails.
140 : *
141 : * @param _level Log level.
142 : *
143 : * @retval true Message shall be compiled in.
144 : * @retval false Message shall removed during the compilation.
145 : */
146 : #define Z_LOG_CONST_LEVEL_CHECK(_level) \
147 : (IS_ENABLED(CONFIG_LOG) && \
148 : (Z_LOG_LEVEL_CHECK(_level, CONFIG_LOG_OVERRIDE_LEVEL, LOG_LEVEL_NONE) \
149 : || \
150 : ((IS_ENABLED(CONFIG_LOG_OVERRIDE_LEVEL) == false) && \
151 : ((_level) <= __log_level) && \
152 : ((_level) <= CONFIG_LOG_MAX_LEVEL) \
153 : ) \
154 : ))
155 :
156 : /** @brief Static level checking for instance logging.
157 : *
158 : * This check applies only to instance logging and only if runtime filtering
159 : * is disabled. It is performed in runtime but because level comes from the
160 : * structure which is constant it is not exact runtime filtering because it
161 : * cannot be changed in runtime.
162 : *
163 : * @param _level Log level.
164 : * @param _inst 1 is source is the instance of a module.
165 : * @param _source Data associated with the instance.
166 : *
167 : * @retval true Continue with log message creation.
168 : * @retval false Drop that message.
169 : */
170 : #define Z_LOG_STATIC_INST_LEVEL_CHECK(_level, _inst, _source) \
171 : (IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) || !_inst || \
172 : (_level <= ((const struct log_source_const_data *)_source)->level))
173 :
174 : /** @brief Dynamic level checking.
175 : *
176 : * It uses the level from the dynamic structure.
177 : *
178 : * @param _level Log level.
179 : * @param _source Data associated with the source.
180 : *
181 : * @retval true Continue with log message creation.
182 : * @retval false Drop that message.
183 : */
184 : #define Z_LOG_DYNAMIC_LEVEL_CHECK(_level, _source) \
185 : (!IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) || k_is_user_context() || \
186 : ((_level) <= Z_LOG_RUNTIME_FILTER(((struct log_source_dynamic_data *)_source)->filters)))
187 :
188 : /** @brief Check if message shall be created.
189 : *
190 : * Aggregate all checks into a single one.
191 : *
192 : * @param _level Log level.
193 : * @param _inst 1 is source is the instance of a module.
194 : * @param _source Data associated with the source.
195 : *
196 : * @retval true Continue with log message creation.
197 : * @retval false Drop that message.
198 : */
199 : #define Z_LOG_LEVEL_ALL_CHECK(_level, _inst, _source) \
200 : (Z_LOG_CONST_LEVEL_CHECK(_level) && \
201 : Z_LOG_STATIC_INST_LEVEL_CHECK(_level, _inst, _source) && \
202 : Z_LOG_DYNAMIC_LEVEL_CHECK(_level, _source))
203 :
204 : /** @brief Get current module data that is used for source id retrieving.
205 : *
206 : * If runtime filtering is used then pointer to dynamic data is returned and else constant
207 : * data is used.
208 : */
209 : #define Z_LOG_CURRENT_DATA() \
210 : COND_CODE_1(CONFIG_LOG_RUNTIME_FILTERING, \
211 : (__log_current_dynamic_data), (__log_current_const_data))
212 :
213 : /*****************************************************************************/
214 : /****************** Definitions used by minimal logging *********************/
215 : /*****************************************************************************/
216 : void z_log_minimal_hexdump_print(int level, const void *data, size_t size);
217 : void z_log_minimal_vprintk(const char *fmt, va_list ap);
218 : void z_log_minimal_printk(const char *fmt, ...);
219 :
220 : #define Z_LOG_TO_PRINTK(_level, fmt, ...) do { \
221 : z_log_minimal_printk("%c: " fmt "\n", \
222 : z_log_minimal_level_to_char(_level), \
223 : ##__VA_ARGS__); \
224 : } while (false)
225 :
226 : #define Z_LOG_TO_VPRINTK(_level, fmt, valist) do { \
227 : z_log_minimal_printk("%c: ", z_log_minimal_level_to_char(_level)); \
228 : z_log_minimal_vprintk(fmt, valist); \
229 : z_log_minimal_printk("\n"); \
230 : } while (false)
231 :
232 : static inline char z_log_minimal_level_to_char(int level)
233 : {
234 : switch (level) {
235 : case LOG_LEVEL_ERR:
236 : return 'E';
237 : case LOG_LEVEL_WRN:
238 : return 'W';
239 : case LOG_LEVEL_INF:
240 : return 'I';
241 : case LOG_LEVEL_DBG:
242 : return 'D';
243 : default:
244 : return '?';
245 : }
246 : }
247 :
248 : #define Z_LOG_INST(_inst) COND_CODE_1(CONFIG_LOG, (_inst), NULL)
249 :
250 : /* If strings are removed from the binary then there is a risk of creating invalid
251 : * cbprintf package if %p is used with character pointer which is interpreted as
252 : * string. A compile time check is performed (since format string is known at
253 : * compile time) and check fails logging message is not created but error is
254 : * emitted instead. String check may increase compilation time so it is not
255 : * always performed (could significantly increase CI time).
256 : */
257 : #ifdef CONFIG_LOG_FMT_STRING_VALIDATE
258 : #define LOG_STRING_WARNING(_mode, _src, ...) \
259 : Z_LOG_MSG_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \
260 : Z_LOG_LOCAL_DOMAIN_ID, _src, LOG_LEVEL_ERR, NULL, 0, \
261 : "char pointer used for %%p, cast to void *:\"%s\"", \
262 : GET_ARG_N(1, __VA_ARGS__))
263 :
264 : #define LOG_POINTERS_VALIDATE(string_ok, ...) \
265 : TOOLCHAIN_DISABLE_GCC_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH); \
266 : string_ok = Z_CBPRINTF_POINTERS_VALIDATE(__VA_ARGS__); \
267 : TOOLCHAIN_ENABLE_GCC_WARNING(TOOLCHAIN_WARNING_POINTER_ARITH);
268 : #else
269 0 : #define LOG_POINTERS_VALIDATE(string_ok, ...) string_ok = true
270 0 : #define LOG_STRING_WARNING(_mode, _src, ...)
271 : #endif
272 :
273 : /*****************************************************************************/
274 : /****************** Macros for standard logging ******************************/
275 : /*****************************************************************************/
276 : /** @internal
277 : * @brief Generic logging macro.
278 : *
279 : * It checks against static levels (resolved at compile timer), runtime levels
280 : * and modes and dispatch to relevant processing path.
281 : *
282 : * @param _level Log message severity level.
283 : *
284 : * @param _inst Set to 1 for instance specific log message. 0 otherwise.
285 : * @param _source Pointer to a structure associated with the module or instance.
286 : * If it is a module then it is used only when runtime filtering is
287 : * enabled. If it is instance then it is used in both cases.
288 : *
289 : * @param ... String with arguments.
290 : */
291 : #define Z_LOG2(_level, _inst, _source, ...) \
292 : TOOLCHAIN_DISABLE_CLANG_WARNING(TOOLCHAIN_WARNING_USED_BUT_MARKED_UNUSED) \
293 : do { \
294 : if (!Z_LOG_LEVEL_ALL_CHECK(_level, _inst, _source)) { \
295 : break; \
296 : } \
297 : if (IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) { \
298 : Z_LOG_TO_PRINTK(_level, __VA_ARGS__); \
299 : break; \
300 : } \
301 : int _mode; \
302 : bool string_ok; \
303 : LOG_POINTERS_VALIDATE(string_ok, __VA_ARGS__); \
304 : if (!string_ok) { \
305 : LOG_STRING_WARNING(_mode, _source, __VA_ARGS__); \
306 : break; \
307 : } \
308 : Z_LOG_MSG_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \
309 : Z_LOG_LOCAL_DOMAIN_ID, _source, _level, NULL, 0, __VA_ARGS__); \
310 : (void)_mode; \
311 : if (false) { \
312 : /* Arguments checker present but never evaluated.*/ \
313 : /* Placed here to ensure that __VA_ARGS__ are*/ \
314 : /* evaluated once when log is enabled.*/ \
315 : z_log_printf_arg_checker(__VA_ARGS__); \
316 : } \
317 : } while (false) \
318 : TOOLCHAIN_ENABLE_CLANG_WARNING(TOOLCHAIN_WARNING_USED_BUT_MARKED_UNUSED)
319 :
320 : #define Z_LOG(_level, ...) Z_LOG2(_level, 0, Z_LOG_CURRENT_DATA(), __VA_ARGS__)
321 : #define Z_LOG_INSTANCE(_level, _inst, ...) Z_LOG2(_level, 1, Z_LOG_INST(_inst), __VA_ARGS__)
322 :
323 : /*****************************************************************************/
324 : /****************** Macros for hexdump logging *******************************/
325 : /*****************************************************************************/
326 : /** @internal
327 : * @brief Generic logging macro.
328 : *
329 : * It checks against static levels (resolved at compile timer), runtime levels
330 : * and modes and dispatch to relevant processing path.
331 : *
332 : * @param _level Log message severity level.
333 : *
334 : * @param _inst Set to 1 for instance specific log message. 0 otherwise.
335 : *
336 : * @param _source Pointer to a structure associated with the module or instance.
337 : * If it is a module then it is used only when runtime filtering is
338 : * enabled. If it is instance then it is used in both cases.
339 : *
340 : * @param _data Hexdump data;
341 : *
342 : * @param _len Hexdump data length.
343 : *
344 : * @param ... String.
345 : */
346 : #define Z_LOG_HEXDUMP2(_level, _inst, _source, _data, _len, ...) \
347 : TOOLCHAIN_DISABLE_CLANG_WARNING(TOOLCHAIN_WARNING_USED_BUT_MARKED_UNUSED) \
348 : do { \
349 : if (!Z_LOG_LEVEL_ALL_CHECK(_level, _inst, _source)) { \
350 : break; \
351 : } \
352 : const char *_str = GET_ARG_N(1, __VA_ARGS__); \
353 : if (IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) { \
354 : Z_LOG_TO_PRINTK(_level, "%s", _str); \
355 : z_log_minimal_hexdump_print((_level), (const char *)(_data), (_len)); \
356 : break; \
357 : } \
358 : int _mode; \
359 : Z_LOG_MSG_CREATE(UTIL_NOT(IS_ENABLED(CONFIG_USERSPACE)), _mode, \
360 : Z_LOG_LOCAL_DOMAIN_ID, _source, _level, _data, _len, \
361 : COND_CODE_0(NUM_VA_ARGS_LESS_1(_, ##__VA_ARGS__), \
362 : (), \
363 : (COND_CODE_0(NUM_VA_ARGS_LESS_1(__VA_ARGS__), \
364 : ("%s", __VA_ARGS__), (__VA_ARGS__))))); \
365 : (void)_mode; \
366 : } while (false) \
367 : TOOLCHAIN_ENABLE_CLANG_WARNING(TOOLCHAIN_WARNING_USED_BUT_MARKED_UNUSED)
368 :
369 : #define Z_LOG_HEXDUMP(_level, _data, _length, ...) \
370 : Z_LOG_HEXDUMP2(_level, 0, Z_LOG_CURRENT_DATA(), _data, _length, __VA_ARGS__)
371 :
372 : #define Z_LOG_HEXDUMP_INSTANCE(_level, _inst, _data, _length, ...) \
373 : Z_LOG_HEXDUMP2(_level, 1, Z_LOG_INST(_inst), _data, _length, __VA_ARGS__)
374 :
375 : /*****************************************************************************/
376 : /****************** Filtering macros *****************************************/
377 : /*****************************************************************************/
378 :
379 : /** @brief Number of bits used to encode log level. */
380 1 : #define LOG_LEVEL_BITS 3U
381 :
382 : /** @brief Filter slot size. */
383 1 : #define LOG_FILTER_SLOT_SIZE LOG_LEVEL_BITS
384 :
385 : /** @brief Number of slots in one word. */
386 1 : #define LOG_FILTERS_NUM_OF_SLOTS (32 / LOG_FILTER_SLOT_SIZE)
387 :
388 : /** @brief Maximum number of backends supported when runtime filtering is enabled. */
389 1 : #define LOG_FILTERS_MAX_BACKENDS \
390 : (LOG_FILTERS_NUM_OF_SLOTS - (1 + IS_ENABLED(CONFIG_LOG_FRONTEND)))
391 :
392 : /** @brief Slot reserved for the frontend. Last slot is used. */
393 1 : #define LOG_FRONTEND_SLOT_ID (LOG_FILTERS_NUM_OF_SLOTS - 1)
394 :
395 : /** @brief Slot mask. */
396 1 : #define LOG_FILTER_SLOT_MASK (BIT(LOG_FILTER_SLOT_SIZE) - 1U)
397 :
398 : /** @brief Bit offset of a slot.
399 : *
400 : * @param _id Slot ID.
401 : */
402 1 : #define LOG_FILTER_SLOT_SHIFT(_id) (LOG_FILTER_SLOT_SIZE * (_id))
403 :
404 0 : #define LOG_FILTER_SLOT_GET(_filters, _id) \
405 : ((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK)
406 :
407 0 : #define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \
408 : do { \
409 : uint32_t others = *(_filters) & ~(LOG_FILTER_SLOT_MASK << \
410 : LOG_FILTER_SLOT_SHIFT(_id)); \
411 : *(_filters) = others | (((_filter) & LOG_FILTER_SLOT_MASK) << \
412 : LOG_FILTER_SLOT_SHIFT(_id)); \
413 : } while (false)
414 :
415 0 : #define LOG_FILTER_AGGR_SLOT_IDX 0
416 :
417 0 : #define LOG_FILTER_AGGR_SLOT_GET(_filters) \
418 : LOG_FILTER_SLOT_GET(_filters, LOG_FILTER_AGGR_SLOT_IDX)
419 :
420 0 : #define LOG_FILTER_FIRST_BACKEND_SLOT_IDX 1
421 :
422 : /* Return aggregated (highest) level for all enabled backends, e.g. if there
423 : * are 3 active backends, one backend is set to get INF logs from a module and
424 : * two other backends are set for ERR, returned level is INF.
425 : */
426 : #define Z_LOG_RUNTIME_FILTER(_filter) \
427 : LOG_FILTER_SLOT_GET(&(_filter), LOG_FILTER_AGGR_SLOT_IDX)
428 :
429 : /** @brief Log level value used to indicate log entry that should not be
430 : * formatted (raw string).
431 : */
432 1 : #define LOG_LEVEL_INTERNAL_RAW_STRING LOG_LEVEL_NONE
433 :
434 0 : TYPE_SECTION_START_EXTERN(struct log_source_const_data, log_const);
435 0 : TYPE_SECTION_END_EXTERN(struct log_source_const_data, log_const);
436 :
437 : /** @brief Create message for logging printk-like string or a raw string.
438 : *
439 : * Part of printk string processing is appending of carriage return after any
440 : * new line character found in the string. If it is not desirable then @p _is_raw
441 : * can be set to 1 to indicate raw string. This information is stored in the source
442 : * field which is not used for its typical purpose in this case.
443 : *
444 : * @param _is_raw Set to 1 to indicate raw string, set to 0 to indicate printk.
445 : * @param ... Format string with arguments.
446 : */
447 : #define Z_LOG_PRINTK(_is_raw, ...) do { \
448 : if (!IS_ENABLED(CONFIG_LOG)) { \
449 : break; \
450 : } \
451 : if (IS_ENABLED(CONFIG_LOG_MODE_MINIMAL)) { \
452 : z_log_minimal_printk(__VA_ARGS__); \
453 : break; \
454 : } \
455 : int _mode; \
456 : if (0) {\
457 : z_log_printf_arg_checker(__VA_ARGS__); \
458 : } \
459 : Z_LOG_MSG_CREATE(!IS_ENABLED(CONFIG_USERSPACE), _mode, \
460 : Z_LOG_LOCAL_DOMAIN_ID, (const void *)(uintptr_t)_is_raw, \
461 : LOG_LEVEL_INTERNAL_RAW_STRING, NULL, 0, __VA_ARGS__);\
462 : } while (0)
463 :
464 : /** @brief Get index of the log source based on the address of the constant data
465 : * associated with the source.
466 : *
467 : * @param data Address of the constant data.
468 : *
469 : * @return Source ID.
470 : */
471 1 : static inline uint32_t log_const_source_id(
472 : const struct log_source_const_data *data)
473 : {
474 : return ((const uint8_t *)data - (uint8_t *)TYPE_SECTION_START(log_const))/
475 : sizeof(struct log_source_const_data);
476 : }
477 :
478 0 : TYPE_SECTION_START_EXTERN(struct log_source_dynamic_data, log_dynamic);
479 0 : TYPE_SECTION_END_EXTERN(struct log_source_dynamic_data, log_dynamic);
480 :
481 : /** @brief Creates name of variable and section for runtime log data.
482 : *
483 : * @param _name Name.
484 : */
485 1 : #define LOG_ITEM_DYNAMIC_DATA(_name) UTIL_CAT(log_dynamic_, _name)
486 :
487 0 : #define LOG_INSTANCE_DYNAMIC_DATA(_module_name, _inst) \
488 : LOG_ITEM_DYNAMIC_DATA(Z_LOG_INSTANCE_FULL_NAME(_module_name, _inst))
489 :
490 : /** @brief Get index of the log source based on the address of the dynamic data
491 : * associated with the source.
492 : *
493 : * @param data Address of the dynamic data.
494 : *
495 : * @return Source ID.
496 : */
497 1 : static inline uint32_t log_dynamic_source_id(struct log_source_dynamic_data *data)
498 : {
499 : return ((uint8_t *)data - (uint8_t *)TYPE_SECTION_START(log_dynamic))/
500 : sizeof(struct log_source_dynamic_data);
501 : }
502 :
503 : /** @brief Get index of the log source based on the address of the associated data.
504 : *
505 : * @param source Address of the data structure (dynamic if runtime filtering is
506 : * enabled and static otherwise).
507 : *
508 : * @return Source ID.
509 : */
510 1 : static inline uint32_t log_source_id(const void *source)
511 : {
512 : return IS_ENABLED(CONFIG_LOG_RUNTIME_FILTERING) ?
513 : log_dynamic_source_id((struct log_source_dynamic_data *)source) :
514 : log_const_source_id((const struct log_source_const_data *)source);
515 : }
516 :
517 : /** @brief Dummy function to trigger log messages arguments type checking. */
518 : static inline __printf_like(1, 2)
519 : void z_log_printf_arg_checker(const char *fmt, ...)
520 : {
521 : ARG_UNUSED(fmt);
522 : }
523 :
524 : /**
525 : * @brief Write a generic log message.
526 : *
527 : * @note This function is intended to be used when porting other log systems.
528 : *
529 : * @param level Log level..
530 : * @param fmt String to format.
531 : * @param ap Pointer to arguments list.
532 : */
533 1 : static inline void log_generic(uint8_t level, const char *fmt, va_list ap)
534 : {
535 : z_log_msg_runtime_vcreate(Z_LOG_LOCAL_DOMAIN_ID, NULL, level,
536 : NULL, 0, 0, fmt, ap);
537 : }
538 :
539 : #ifdef __cplusplus
540 : }
541 : #endif
542 :
543 : #endif /* ZEPHYR_INCLUDE_LOGGING_LOG_CORE_H_ */
|