John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 1 | #ifndef AOS_LOGGING_INTERFACE_H_ |
| 2 | #define AOS_LOGGING_INTERFACE_H_ |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 3 | |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cstdarg> |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 5 | #include <functional> |
Tyler Chatow | 4b471e1 | 2020-01-05 20:19:36 -0800 | [diff] [blame] | 6 | #include <string> |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 7 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 8 | #include "aos/logging/logging.h" |
| 9 | #include "aos/macros.h" |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 10 | |
Brian Silverman | cb5da1f | 2015-12-05 22:19:58 -0500 | [diff] [blame] | 11 | // This file has the non-C-compatible parts of the logging client interface. |
| 12 | |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 13 | namespace aos { |
| 14 | |
| 15 | struct MessageType; |
| 16 | |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 17 | namespace logging { |
| 18 | |
Brian Silverman | 17291d8 | 2015-10-24 22:30:57 -0400 | [diff] [blame] | 19 | // Takes a message and logs it. It will set everything up and then call DoLog |
| 20 | // for the current LogImplementation. |
| 21 | void VLog(log_level level, const char *format, va_list ap) |
| 22 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 2, 0))); |
Brian Silverman | 17291d8 | 2015-10-24 22:30:57 -0400 | [diff] [blame] | 23 | |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 24 | // Represents a system that can actually take log messages and do something |
| 25 | // useful with them. |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 26 | class LogImplementation { |
| 27 | public: |
Tyler Chatow | 4b471e1 | 2020-01-05 20:19:36 -0800 | [diff] [blame] | 28 | LogImplementation() {} |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 29 | |
Tyler Chatow | 4b471e1 | 2020-01-05 20:19:36 -0800 | [diff] [blame] | 30 | virtual ~LogImplementation() {} |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 31 | |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 32 | // Actually logs the given message. Implementations should somehow create a |
| 33 | // LogMessage and then call internal::FillInMessage. |
Tyler Chatow | 4b471e1 | 2020-01-05 20:19:36 -0800 | [diff] [blame] | 34 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0))) virtual void DoLog( |
| 35 | log_level level, const char *format, va_list ap) = 0; |
| 36 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 4))) void DoLogVariadic( |
| 37 | log_level level, const char *format, ...) { |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 38 | va_list ap; |
| 39 | va_start(ap, format); |
| 40 | DoLog(level, format, ap); |
| 41 | va_end(ap); |
| 42 | } |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
Brian Silverman | 17291d8 | 2015-10-24 22:30:57 -0400 | [diff] [blame] | 45 | namespace internal { |
| 46 | |
| 47 | // Prints format (with ap) into output and correctly deals with the result |
| 48 | // being too long etc. |
| 49 | size_t ExecuteFormat(char *output, size_t output_size, const char *format, |
| 50 | va_list ap) |
| 51 | __attribute__((format(GOOD_PRINTF_FORMAT_TYPE, 3, 0))); |
| 52 | |
Brian Silverman | 17291d8 | 2015-10-24 22:30:57 -0400 | [diff] [blame] | 53 | } // namespace internal |
Austin Schuh | 044e18b | 2015-10-21 20:17:09 -0700 | [diff] [blame] | 54 | } // namespace logging |
| 55 | } // namespace aos |
| 56 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 57 | #endif // AOS_LOGGING_INTERFACE_H_ |