AceTime  3.0.0
Date and time classes for Arduino that support timezones from the TZ Database.
logging.h
1 /*
2  * MIT License
3  * Copyright (c) 2018 Brian T. Park
4  */
5 
6 /*
7  * Implement logging::printf() that accept formatting strings like printf(). I
8  * finally got tired of writing multiple lines of SERIAL_PORT_MONITOR.print()
9  * for debugging.
10  *
11  * NOTE: These *must* be implemented as inline function to allow the compiler
12  * to remove unused functions from the binary. For some reason, on AVR, ESP8266
13  * and ESP32 compilers, link-time-optimization does not seem to work well. If
14  * these functions are defined in a .cpp file, they are included in the binary,
15  * even if they are not reference at all by anything. This causes the binary to
16  * be about 700 (AVR) to 1000 (ESP32) bytes larger in flash memory. Being
17  * inlined here means that <Arduino.h> must be included here, which can cause
18  * some problems in files that try to clobber macros defined in <Ardhino.h>.
19  */
20 
21 #ifndef ACE_TIME_COMMON_LOGGING_H
22 #define ACE_TIME_COMMON_LOGGING_H
23 
24 #include <stdarg.h> // va_list, va_start(), va_end()
25 #include <Arduino.h> // SERIAL_PORT_MONITOR
26 #include <AceCommon.h> // vprintfTo()
27 
28 // ESP32 does not define SERIAL_PORT_MONITOR
29 #ifndef SERIAL_PORT_MONITOR
30 #define SERIAL_PORT_MONITOR Serial
31 #endif
32 
33 namespace ace_time {
34 namespace logging {
35 
42 inline void printf(const char* fmt, ...) {
43  va_list args;
44  va_start(args, fmt);
45  ace_common::vprintfTo(SERIAL_PORT_MONITOR, fmt, args);
46  va_end(args);
47 }
48 
49 }
50 }
51 
52 #endif