C/C++ API Reference
Loading...
Searching...
No Matches
config.h
1// Copyright 2021 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_log/levels.h"
17#include "pw_log/options.h"
18#include "pw_polyfill/static_assert.h"
19#include "pw_tokenizer/config.h"
20
22
23// The size of the stack-allocated argument encoding buffer to use by default.
24// A buffer of this size is allocated and used for the 4-byte token and for
25// encoding all arguments. It must be at least large enough for the token (4
26// bytes).
27//
28// This buffer does not need to be large to accommodate a good number of
29// tokenized string arguments. Integer arguments are usually encoded smaller
30// than their native size (e.g. 1 or 2 bytes for smaller numbers). All floating
31// point types are encoded as four bytes. Null-terminated strings are encoded
32// 1:1 in size, however, and can quickly fill up this buffer.
33#ifndef PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES
34#define PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES \
35 PW_TOKENIZER_CFG_ENCODING_BUFFER_SIZE_BYTES
36#endif // PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES
37
38#define PW_LOG_TOKENIZED_FIELD_PREFIX "■"
39#define PW_LOG_TOKENIZED_KEY_VALUE_SEPARATOR "♦"
40
41// This macro takes the PW_LOG format string and optionally transforms it. By
42// default, pw_log_tokenized specifies three fields as key-value pairs.
43#ifndef PW_LOG_TOKENIZED_FORMAT_STRING
44
45#define _PW_LOG_TOKENIZED_FIELD(name, contents) \
46 PW_LOG_TOKENIZED_FIELD_PREFIX name PW_LOG_TOKENIZED_KEY_VALUE_SEPARATOR \
47 contents
48
54#define PW_LOG_TOKENIZED_FORMAT_STRING(module, message) \
55 _PW_LOG_TOKENIZED_FIELD("msg", message) \
56 _PW_LOG_TOKENIZED_FIELD("module", module) \
57 _PW_LOG_TOKENIZED_FIELD("file", __FILE__)
58
59#endif // PW_LOG_TOKENIZED_FORMAT_STRING
60
61// The log level, line number, flag bits, and module token are packed into the
62// tokenizer's payload argument, which is typically 32 bits. These macros
63// specify the number of bits to use for each field. A field with zero bits is
64// excluded.
65
68#ifndef PW_LOG_TOKENIZED_LEVEL_BITS
69#define PW_LOG_TOKENIZED_LEVEL_BITS PW_LOG_LEVEL_BITS
70#endif // PW_LOG_TOKENIZED_LEVEL_BITS
71
86#ifndef PW_LOG_TOKENIZED_LINE_BITS
87#define PW_LOG_TOKENIZED_LINE_BITS 11
88#endif // PW_LOG_TOKENIZED_LINE_BITS
89
91#ifndef PW_LOG_TOKENIZED_FLAG_BITS
92#define PW_LOG_TOKENIZED_FLAG_BITS 2
93#endif // PW_LOG_TOKENIZED_FLAG_BITS
94
98#ifndef PW_LOG_TOKENIZED_MODULE_BITS
99#define PW_LOG_TOKENIZED_MODULE_BITS 16
100#endif // PW_LOG_TOKENIZED_MODULE_BITS
101
104 "Log metadata fields must use 32 bits");
105
106#ifdef __cplusplus
107
108#include <cstddef>
109
110namespace pw::log_tokenized {
111
112// C++ constant for the encoding buffer size. Use this instead of the macro.
113inline constexpr size_t kEncodingBufferSizeBytes =
114 PW_LOG_TOKENIZED_ENCODING_BUFFER_SIZE_BYTES;
115
116} // namespace pw::log_tokenized
117
118#endif // __cplusplus
#define PW_LOG_TOKENIZED_LINE_BITS
Definition: config.h:87
#define PW_LOG_TOKENIZED_MODULE_BITS
Definition: config.h:99
#define PW_LOG_TOKENIZED_LEVEL_BITS
Definition: config.h:69
#define PW_LOG_TOKENIZED_FLAG_BITS
Bits to use for implementation-defined flags. Defaults to 2.
Definition: config.h:92