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 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. 18 // 19 // For example, the following sets the log module name to "Foobar" and the 20 // minimum log level to WARN: 21 // 22 // #define PW_LOG_MODULE_NAME "Foobar" 23 // #define PW_LOG_LEVEL PW_LOG_LEVEL_WARN 24 // 25 // #include "foo/bar.h" 26 // #include "pw_log/log.h" 27 // 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. 31 #pragma once 32 33 #include "pw_log/config.h" 34 35 // These configuration options differ from the options in pw_log/config.h in 36 // that these should be set at a module/compile unit level rather than a global 37 // level level. 38 39 // Default: Module name 40 // 41 // An empty string is used for the module name if it is not set. The 42 // PW_LOG_MODULE_NAME_DEFINED macro is set to 1 or 0 to allow pw_log backends to 43 // behave differently if the module name is defined. For example, a backend 44 // might prefix the format string with PW_LOG_MODULE_NAME ": ", but only if the 45 // module name is provided. 46 #ifdef PW_LOG_MODULE_NAME 47 #define PW_LOG_MODULE_NAME_DEFINED 1 48 #else 49 #define PW_LOG_MODULE_NAME "" 50 #define PW_LOG_MODULE_NAME_DEFINED 0 51 #endif // PW_LOG_MODULE_NAME 52 53 // Default: Log level filtering 54 // 55 // All log statements have a level, and this define sets the log level to the 56 // globally set default if PW_LOG_LEVEL was not already set by the module. 57 // This is compile-time filtering if the level is a constant. 58 #ifndef PW_LOG_LEVEL 59 #define PW_LOG_LEVEL PW_LOG_LEVEL_DEFAULT 60 #endif // PW_LOG_LEVEL 61 62 // Default: Flags 63 // 64 // For log statements like LOG_INFO that don't have an explicit argument, this 65 // is used for the flags value. 66 #ifndef PW_LOG_FLAGS 67 #define PW_LOG_FLAGS PW_LOG_FLAGS_DEFAULT 68 #endif // PW_LOG_FLAGS 69 70 // DEPRECATED: Use PW_LOG_FLAGS. 71 // TODO(pwbug/561): Remove this macro after migration. 72 #ifndef PW_LOG_DEFAULT_FLAGS 73 #define PW_LOG_DEFAULT_FLAGS PW_LOG_FLAGS 74 #endif // PW_LOG_DEFAULT_FLAGS 75 76 // Default: Log enabled expression 77 // 78 // This expression determines whether or not the statement is enabled and 79 // should be passed to the backend. 80 #ifndef PW_LOG_ENABLE_IF 81 #define PW_LOG_ENABLE_IF(level, flags) PW_LOG_ENABLE_IF_DEFAULT(level, flags) 82 #endif // PW_LOG_ENABLE_IF 83