1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 #include "pw_preprocessor/arguments.h"
17 #include "pw_preprocessor/compiler.h"
18 #include "pw_preprocessor/util.h"
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
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.
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,
35 const char* module_name,
37 ...) PW_PRINTF_FORMAT(4, 5);
39 static inline void pw_log_Ignored(int level,
41 const char* module_name,
46 PW_UNUSED(module_name);
52 #define PW_LOG(level, flags, message, ...) \
53 pw_log_Ignored((level), \
56 message PW_COMMA_ARGS(__VA_ARGS__))