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 #pragma once 15 16 // Replaces log levels and flag presence indicator with emoji. 17 #ifndef PW_EMOJI 18 #define PW_EMOJI 0 19 #endif // PW_EMOJI 20 21 // With all the following flags enabled except for the optional user provided 22 // PW_LOG_APPEND_TIMESTAMP, log messages look like this: 23 // 24 // clang-format off 25 // my_file.cc : 42 | Foo | TST | INF Hello, world! 26 // buggy.cc :2145 | ReadBuggyBuffer | * ERR No, BAD! 27 // 28 // With emoji: 29 // my_file.cc : 42 | Foo | TST ℹ️ Hello, world! 30 // buggy.cc :2145 | ReadBuggyBuffer | ❌ No, BAD! 31 // clang-format on 32 33 // Prints the name of the file that emitted the log message. 34 #ifndef PW_LOG_SHOW_FILENAME 35 #define PW_LOG_SHOW_FILENAME 0 36 #endif // PW_LOG_SHOW_FILENAME 37 38 // Prints the name of the function that emitted the log message. 39 #ifndef PW_LOG_SHOW_FUNCTION 40 #define PW_LOG_SHOW_FUNCTION 0 41 #endif // PW_LOG_SHOW_FUNCTION 42 43 // Prints an indicator for whether or not there are any active flags for a given 44 // log statement. 45 #ifndef PW_LOG_SHOW_FLAG 46 #define PW_LOG_SHOW_FLAG 0 47 #endif // PW_LOG_SHOW_FLAG 48 49 // Prints the module name associated with a log statement. This is provided by 50 // defining PW_LOG_MODULE_NAME inside module source files, it is not implied by 51 // module structure or file path magic. 52 #ifndef PW_LOG_SHOW_MODULE 53 #define PW_LOG_SHOW_MODULE 0 54 #endif // PW_LOG_SHOW_MODULE 55 56 // Optional user provided macro to append a prefixing timestamp string. 57 // For example this could be implemented as: 58 // #define PW_LOG_APPEND_TIMESTAMP(buffer) AppendSecSinceEpoch(buffer) 59 // 60 // void AppendSecSinceEpoch(pw::StringBuilder& builder) { 61 // const std::chrono::duration<float> float_s_since_epoch = 62 // pw::chrono::SystemClock::now().time_since_epoch(); 63 // builder << float_s_since_epoch.count() << " "; 64 // } 65 #ifndef PW_LOG_APPEND_TIMESTAMP 66 #define PW_LOG_APPEND_TIMESTAMP(buffer) \ 67 do { \ 68 } while (0) 69 #endif // PW_LOG_APPEND_TIMESTAMP 70 71 // Maximum size of the encoded log message. Log messages that would result in a 72 // larger entry are truncated to this size. The message buffer is allocated on 73 // the stack on every log call. 74 #ifndef PW_LOG_BASIC_ENTRY_SIZE 75 #define PW_LOG_BASIC_ENTRY_SIZE 150 76 #endif // PW_LOG_BASIC_ENTRY_SIZE 77