aboutsummaryrefslogtreecommitdiff
path: root/pw_log/public/pw_log/options.h
blob: 87936f6db2267b59bed85cbe95d3210d220cde19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2020 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

// This file defines macros used to control the behavior of pw_log statements.
// Files that use pw_log may define these macros BEFORE any headers are
// #included to customize pw_log.
//
// For example, the following sets the log module name to "Foobar" and the
// minimum log level to WARN:
//
//   #define PW_LOG_MODULE_NAME "Foobar"
//   #define PW_LOG_LEVEL PW_LOG_LEVEL_WARN
//
//   #include "foo/bar.h"
//   #include "pw_log/log.h"
//
// Users of pw_log should not include this header directly; include
// "pw_log/log.h" instead. This header is separate from "pw_log/log.h" to avoid
// circular dependencies when implementing the pw_log facade.
#pragma once

#include "pw_log/config.h"

// These configuration options differ from the options in pw_log/config.h in
// that these should be set at a module/compile unit level rather than a global
// level level.

// Default: Module name
//
// An empty string is used for the module name if it is not set. The
// PW_LOG_MODULE_NAME_DEFINED macro is set to 1 or 0 to allow pw_log backends to
// behave differently if the module name is defined. For example, a backend
// might prefix the format string with PW_LOG_MODULE_NAME ": ", but only if the
// module name is provided.
#ifdef PW_LOG_MODULE_NAME
#define PW_LOG_MODULE_NAME_DEFINED 1
#else
#define PW_LOG_MODULE_NAME ""
#define PW_LOG_MODULE_NAME_DEFINED 0
#endif  // PW_LOG_MODULE_NAME

// Default: Log level filtering
//
// All log statements have a level, and this define sets the log level to the
// globally set default if PW_LOG_LEVEL was not already set by the module.
// This is compile-time filtering if the level is a constant.
#ifndef PW_LOG_LEVEL
#define PW_LOG_LEVEL PW_LOG_LEVEL_DEFAULT
#endif  // PW_LOG_LEVEL

// Default: Flags
//
// For log statements like LOG_INFO that don't have an explicit argument, this
// is used for the flags value.
#ifndef PW_LOG_FLAGS
#define PW_LOG_FLAGS PW_LOG_FLAGS_DEFAULT
#endif  // PW_LOG_FLAGS

// DEPRECATED: Use PW_LOG_FLAGS.
// TODO(b/234876701): Remove this macro after migration.
#ifndef PW_LOG_DEFAULT_FLAGS
#define PW_LOG_DEFAULT_FLAGS PW_LOG_FLAGS
#endif  // PW_LOG_DEFAULT_FLAGS

// Default: Log enabled expression
//
// This expression determines whether or not the statement is enabled and
// should be passed to the backend.
#ifndef PW_LOG_ENABLE_IF
#define PW_LOG_ENABLE_IF(level, module, flags) \
  PW_LOG_ENABLE_IF_DEFAULT(level, module, flags)
#endif  // PW_LOG_ENABLE_IF