xref: /aosp_15_r20/external/pigweed/pw_log_null/public/pw_log_null/log_null.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2020 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 #pragma once
15 
16 #include "pw_preprocessor/arguments.h"
17 #include "pw_preprocessor/compiler.h"
18 #include "pw_preprocessor/util.h"
19 
20 PW_EXTERN_C_START
21 
22 // Empty function for compiling out log statements. Since the function is empty
23 // and inline, it should be completely compiled out. This function accomplishes
24 // following:
25 //
26 //   - Uses the arguments to PW_LOG, which avoids "unused variable" warnings.
27 //   - Executes expressions passed to PW_LOG, so that the behavior is consistent
28 //     between this null backend and a backend that actually logs.
29 //   - Checks the printf-style format string arguments to PW_LOG.
30 //
31 // For compatibility with C and the printf compiler attribute, the declaration
32 // and definition must be separate and both marked inline.
33 static inline void pw_log_Ignored(int level,
34                                   const char* module_name,
35                                   unsigned int flags,
36                                   const char* message,
37                                   ...) PW_PRINTF_FORMAT(4, 5);
38 
pw_log_Ignored(int level,const char * module_name,unsigned int flags,const char * message,...)39 static inline void pw_log_Ignored(int level,
40                                   const char* module_name,
41                                   unsigned int flags,
42                                   const char* message,
43                                   ...) {
44   (void)level;
45   (void)module_name;
46   (void)flags;
47   (void)message;
48 }
49 
50 PW_EXTERN_C_END
51 
52 #define PW_HANDLE_LOG(level, module, flags, message, ...) \
53   pw_log_Ignored((level), module, (flags), message PW_COMMA_ARGS(__VA_ARGS__))
54