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
15 // This file defines macros used to control the behavior of pw_log statements.
16 // Files that use pw_log may define these macros BEFORE any headers are
17 // #included to customize pw_log.
19 // For example, the following sets the log module name to "Foobar" and the
20 // minimum log level to WARN:
22 // #define PW_LOG_MODULE_NAME "Foobar"
23 // #define PW_LOG_LEVEL PW_LOG_LEVEL_WARN
25 // #include "foo/bar.h"
26 // #include "pw_log/log.h"
28 // Users of pw_log should not include this header directly; include
29 // "pw_log/log.h" instead. This header is separate from "pw_log/log.h" to avoid
30 // circular dependencies when implementing the pw_log facade.
33 // Default: Module name
35 // An empty string is used for the module name if it is not set. The
36 // PW_LOG_MODULE_NAME_DEFINED macro is set to 1 or 0 to allow pw_log backends to
37 // behave differently if the module name is defined. For example, a backend
38 // might prefix the format string with PW_LOG_MODULE_NAME ": ", but only if the
39 // module name is provided.
40 #ifdef PW_LOG_MODULE_NAME
41 #define PW_LOG_MODULE_NAME_DEFINED 1
43 #define PW_LOG_MODULE_NAME ""
44 #define PW_LOG_MODULE_NAME_DEFINED 0
45 #endif // PW_LOG_MODULE_NAME
49 // For log statements like LOG_INFO that don't have an explicit argument, this
50 // is used for the flags value.
51 #ifndef PW_LOG_DEFAULT_FLAGS
52 #define PW_LOG_DEFAULT_FLAGS 0
53 #endif // PW_LOG_DEFAULT_FLAGS
55 // Default: Log level filtering
57 // All log statements have a level, and this define is the default filtering.
58 // This is compile-time filtering if the level is a constant.
60 #define PW_LOG_LEVEL PW_LOG_LEVEL_DEBUG
61 #endif // PW_LOG_LEVEL
63 // Default: Log enabled expression
65 // This expression determines whether or not the statement is enabled and
66 // should be passed to the backend.
67 #ifndef PW_LOG_ENABLE_IF
68 #define PW_LOG_ENABLE_IF(level, flags) ((level) >= PW_LOG_LEVEL)
69 #endif // PW_LOG_ENABLE_IF