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 <assert.h> 17 18 #include "pw_log/options.h" 19 #include "pw_preprocessor/concat.h" 20 21 // This macro takes the PW_LOG format string and optionally transforms it. By 22 // default, the PW_LOG_MODULE_NAME is prepended to the string if present. 23 #ifndef PW_LOG_TOKENIZED_FORMAT_STRING 24 25 #define PW_LOG_TOKENIZED_FORMAT_STRING(string) \ 26 PW_CONCAT(PW_LOG_TOKENIZED_FMT_, PW_LOG_MODULE_NAME_DEFINED)(string) 27 28 #define PW_LOG_TOKENIZED_FMT_0(string) string 29 #define PW_LOG_TOKENIZED_FMT_1(string) PW_LOG_MODULE_NAME " " string 30 31 #endif // PW_LOG_TOKENIZED_FORMAT_STRING 32 33 // The log level, module token, and flag bits are packed into the tokenizer's 34 // payload argument, which is typically 32 bits. These macros specify the number 35 // of bits to use for each field. 36 #ifndef PW_LOG_TOKENIZED_LEVEL_BITS 37 #define PW_LOG_TOKENIZED_LEVEL_BITS 6 38 #endif // PW_LOG_TOKENIZED_LEVEL_BITS 39 40 #ifndef PW_LOG_TOKENIZED_MODULE_BITS 41 #define PW_LOG_TOKENIZED_MODULE_BITS 16 42 #endif // PW_LOG_TOKENIZED_MODULE_BITS 43 44 #ifndef PW_LOG_TOKENIZED_FLAG_BITS 45 #define PW_LOG_TOKENIZED_FLAG_BITS 10 46 #endif // PW_LOG_TOKENIZED_FLAG_BITS 47 48 static_assert((PW_LOG_TOKENIZED_LEVEL_BITS + PW_LOG_TOKENIZED_MODULE_BITS + 49 PW_LOG_TOKENIZED_FLAG_BITS) == 32, 50 "Log metadata must fit in a 32-bit integer"); 51 52 // The macro to use to tokenize the log and its arguments. Defaults to 53 // PW_TOKENIZE_TO_GLOBAL_HANDLER_WITH_PAYLOAD. Projects may define their own 54 // version of this macro that uses a different underlying function, if desired. 55 #ifndef PW_LOG_TOKENIZED_ENCODE_MESSAGE 56 #define PW_LOG_TOKENIZED_ENCODE_MESSAGE \ 57 PW_TOKENIZE_TO_GLOBAL_HANDLER_WITH_PAYLOAD 58 #endif // PW_LOG_TOKENIZED_ENCODE_MESSAGE 59