• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(b/235289435): Reconsider the naming of this module when more is in
42 // place.
43 #define PW_HANDLE_LOG(level, module, flags, message, ...) \
44   do {                                                    \
45     pw_Log((level),                                       \
46            (flags),                                       \
47            module,                                        \
48            __FILE__,                                      \
49            __LINE__,                                      \
50            __func__,                                      \
51            message PW_COMMA_ARGS(__VA_ARGS__));           \
52   } while (0)
53 
54 #ifdef __cplusplus
55 
56 #include <string_view>
57 
58 namespace pw::log_basic {
59 
60 // Sets the function to use to send log messages. Defaults to
61 // pw::sys_io::WriteLine.
62 void SetOutput(void (*log_output)(std::string_view log));
63 
64 }  // namespace pw::log_basic
65 
66 #endif  // __cplusplus
67