1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
16 // Replaces log levels and flag presence indicator with emoji.
21 // With all the following flags enabled except for the optional user provided
22 // PW_LOG_APPEND_TIMESTAMP, log messages look like this:
25 // my_file.cc : 42 | Foo | TST | INF Hello, world!
26 // buggy.cc :2145 | ReadBuggyBuffer | * ERR No, BAD!
29 // my_file.cc : 42 | Foo | TST ℹ️ Hello, world!
30 // buggy.cc :2145 | ReadBuggyBuffer | 🚩 ❌ No, BAD!
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
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
43 // Prints an indicator for whether or not there are any active flags for a given
45 #ifndef PW_LOG_SHOW_FLAG
46 #define PW_LOG_SHOW_FLAG 0
47 #endif // PW_LOG_SHOW_FLAG
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
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)
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() << " ";
65 #ifndef PW_LOG_APPEND_TIMESTAMP
66 #define PW_LOG_APPEND_TIMESTAMP(buffer) \
69 #endif // PW_LOG_APPEND_TIMESTAMP