Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_log_basic / public / pw_log_basic / log_basic.h
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 #include "pw_preprocessor/arguments.h"
17 #include "pw_preprocessor/compiler.h"
18 #include "pw_preprocessor/util.h"
19
20 PW_EXTERN_C_START
21
22 // Log a message with the listed attributes.
23 void pw_Log(int level,
24             unsigned int flags,
25             const char* module_name,
26             const char* file_name,
27             int line_number,
28             const char* function_name,
29             const char* message,
30             ...) PW_PRINTF_FORMAT(7, 8);
31
32 PW_EXTERN_C_END
33
34 // Log a message with many attributes included.
35 //
36 // This is the log macro frontend that funnels everything into the C handler
37 // above, pw_Log(). It's not efficient at the callsite, since it passes many
38 // arguments. Additionally, the use of the __FUNC__ macro adds a static const
39 // char[] variable inside functions with a log.
40 //
41 // TODO(pwbug/87): Reconsider the naming of this module when more is in place.
42 #define PW_HANDLE_LOG(level, flags, message, ...) \
43   do {                                            \
44     pw_Log((level),                               \
45            (flags),                               \
46            PW_LOG_MODULE_NAME,                    \
47            __FILE__,                              \
48            __LINE__,                              \
49            __func__,                              \
50            message PW_COMMA_ARGS(__VA_ARGS__));   \
51   } while (0)
52
53 #ifdef __cplusplus
54
55 #include <string_view>
56
57 namespace pw::log_basic {
58
59 // Sets the function to use to send log messages. Defaults to
60 // pw::sys_io::WriteLine.
61 void SetOutput(void (*log_output)(std::string_view log));
62
63 }  // namespace pw::log_basic
64
65 #endif  // __cplusplus