Anjay Lite
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*
2 * Copyright 2023-2025 AVSystem <avsystem@avsystem.com>
3 * AVSystem Anjay Lite LwM2M SDK
4 * All rights reserved.
5 *
6 * Licensed under AVSystem Anjay Lite LwM2M Client SDK - Non-Commercial License.
7 * See the attached LICENSE file for details.
8 */
9
10#include <anj/init.h>
11
12#ifndef ANJ_LOG_LOG_H
13# define ANJ_LOG_LOG_H
14
15# include <stdio.h>
16
17# ifdef __cplusplus
18extern "C" {
19# endif
20
21# include <anj/compat/log_impl_decls.h> // IWYU pragma: export
22# include <anj/utils.h>
23
24# define ANJ_INTERNAL_INCLUDE_LOG_FILTERING_UTILS
25# include <anj_internal/log/log_filtering_utils.h>
26# undef ANJ_INTERNAL_INCLUDE_LOG_FILTERING_UTILS
27
35# define ANJ_LOG_PRINTF_ARG_CHECK(...) ((void) sizeof(printf(__VA_ARGS__)))
36
41# define ANJ_LOG_ENFORCE_FORMAT_INLINE_LITERAL(...) "" __VA_ARGS__
42
51# define ANJ_LOG_COMPILE_TIME_CHECK(...) \
52 ANJ_LOG_PRINTF_ARG_CHECK( \
53 ANJ_LOG_ENFORCE_FORMAT_INLINE_LITERAL(__VA_ARGS__))
54
55# ifdef _ANJ_LOG_ENABLED
56
57# ifdef ANJ_LOG_FULL
58# define ANJ_LOG_HANDLER_IMPL_MACRO(Module, LogLevel, ...) \
59 anj_log_handler_impl_full(ANJ_LOG_LEVEL_##LogLevel, \
60 ANJ_QUOTE_MACRO(Module), __FILE__, \
61 __LINE__, __VA_ARGS__)
62# endif // ANJ_LOG_FULL
63
64# ifdef ANJ_LOG_ALT_IMPL_HEADER
65# include ANJ_LOG_ALT_IMPL_HEADER
66# endif // ANJ_LOG_ALT_IMPL_HEADER
67
68# ifdef ANJ_LOG_FILTERING_CONFIG_HEADER
69# include ANJ_LOG_FILTERING_CONFIG_HEADER
70# endif // ANJ_LOG_FILTERING_CONFIG_HEADER
71
72# ifndef ANJ_LOG_LEVEL_DEFAULT
73# define ANJ_LOG_LEVEL_DEFAULT L_INFO
74# endif // ANJ_LOG_LEVEL_DEFAULT
75
76# define ANJ_LOG_IF_ALLOWED_LOOKUP_ANJ_LOG_YES(Module, LogLevel, ...) \
77 ANJ_LOG_HANDLER_IMPL_MACRO(Module, LogLevel, __VA_ARGS__)
78# define ANJ_LOG_IF_ALLOWED_LOOKUP_ANJ_LOG_NO(Module, LogLevel, ...) \
79 ((void) 0)
80
81# define ANJ_LOG_IF_ALLOWED(Module, LogLevel, ...) \
82 ANJ_CONCAT(ANJ_LOG_IF_ALLOWED_LOOKUP_, \
83 _ANJ_LOG_EMIT_CALL(LogLevel, \
84 _ANJ_LOG_MODULE_LEVEL(Module))) \
85 (Module, LogLevel, __VA_ARGS__)
86# else // _ANJ_LOG_ENABLED
87# define ANJ_LOG_IF_ALLOWED(Module, LogLevel, ...) ((void) 0)
88# endif // _ANJ_LOG_ENABLED
89
114# define anj_log(Module, LogLevel, ...) \
115 ((void) (ANJ_LOG_IF_ALLOWED(Module, LogLevel, __VA_ARGS__), \
116 ANJ_LOG_COMPILE_TIME_CHECK(__VA_ARGS__)))
117
118# ifdef ANJ_LOG_STRIP_CONSTANTS
119# define ANJ_LOG_DISPOSABLE_IMPL(Arg) " "
120# else // ANJ_LOG_STRIP_CONSTANTS
121# define ANJ_LOG_DISPOSABLE_IMPL(Arg) Arg
122# endif // ANJ_LOG_STRIP_CONSTANTS
123
137# define ANJ_LOG_DISPOSABLE(Arg) ANJ_LOG_DISPOSABLE_IMPL(Arg)
138
139# ifdef __cplusplus
140}
141# endif
142
143#endif // ANJ_LOG_LOG_H