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 "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_LogSink_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_LogSink_Log(). It's not efficient at the callsite, since it passes 38 // many arguments. Additionally, the use of the __FUNC__ macro adds a static 39 // const 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_LogSink_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 #include "pw_bytes/span.h" 58 #include "pw_log_sink/sink.h" 59 60 namespace pw::log_sink { 61 62 // Adds sink interface to list of sinks to push messages to. 63 void AddSink(Sink& sink); 64 65 // Removes sink interface from list of sinks to push messages to. 66 void RemoveSink(Sink& sink); 67 68 } // namespace pw::log_sink 69 70 #endif // __cplusplus 71