-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathArduinoLogger.h
870 lines (770 loc) · 22.5 KB
/
ArduinoLogger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
#ifndef ARDUINO_LOGGER_H_
#define ARDUINO_LOGGER_H_
#include <LibPrintf.h>
#if !defined(__AVR__)
#include <utility>
#endif
/// Logging is disabled
#define LOG_LEVEL_OFF 0
/// Indicates the system is unusable, or an error that is unrecoverable
#define LOG_LEVEL_CRITICAL 1
/// Indicates an error condition
#define LOG_LEVEL_ERROR 2
/// Indicates a warning condition
#define LOG_LEVEL_WARNING 3
/// Informational messages
#define LOG_LEVEL_INFO 4
/// Debug-level messages
#define LOG_LEVEL_DEBUG 5
/// The maximum log level that can be set
#define LOG_LEVEL_MAX LOG_LEVEL_DEBUG
/// The number of possible log levels
#define LOG_LEVEL_COUNT (LOG_LEVEL_MAX + 1)
#define LOG_LEVEL_CRITICAL_PREFIX "<!> "
#define LOG_LEVEL_ERROR_PREFIX "<E> "
#define LOG_LEVEL_WARNING_PREFIX "<W> "
#define LOG_LEVEL_INFO_PREFIX "<I> "
#define LOG_LEVEL_DEBUG_PREFIX "<D> "
// Supply a default log level
#ifndef LOG_LEVEL
/** Default maximum log level.
*
* This is the maximum log level that will be compiled in.
* To set a custom log level, define the LOG_LEVEL before including this header
* (e.g., as a compiler definition)
*/
#define LOG_LEVEL LOG_LEVEL_DEBUG
#endif
#ifndef LOG_EN_DEFAULT
/// Whether the logging module is enabled automatically on boot.
#define LOG_EN_DEFAULT true
#endif
#ifndef LOG_AUTOFLUSH_DEFAULT
/// Whether the log should auto-flush by default on boot
#define LOG_AUTOFLUSH_DEFAULT true
#endif
#ifndef LOG_ECHO_EN_DEFAULT
/// Indicates that log statements should be echoed to the console
/// If true, log statements will be echoed.
/// If false, log statements will only go to the log.
#define LOG_ECHO_EN_DEFAULT false
#endif
#ifndef LOG_LEVEL_NAMES
/// Users can override these default names with a compiler definition
#define LOG_LEVEL_NAMES \
{ \
"off", "critical", "error", "warning", "info", "debug", \
}
#endif
#ifndef LOG_LEVEL_SHORT_NAMES
/// Users can override these default short names with a compiler definition
#define LOG_LEVEL_SHORT_NAMES \
{ \
"O", LOG_LEVEL_CRITICAL_PREFIX, LOG_LEVEL_ERROR_PREFIX, LOG_LEVEL_WARNING_PREFIX, \
LOG_LEVEL_INFO_PREFIX, LOG_LEVEL_DEBUG_PREFIX, \
}
#endif
#ifndef NO_PRAGMA_MARK
#pragma mark - Short File Name Macro -
#endif
using cstr = const char* const;
constexpr cstr past_last_slash(cstr str, cstr last_slash)
{
return *str == '\0' ? last_slash
: *str == '/' ? past_last_slash(str + 1, str + 1)
: past_last_slash(str + 1, last_slash);
}
constexpr cstr past_last_slash(cstr str)
{
return past_last_slash(str, str);
}
#define __SHORT_FILE__ \
({ \
constexpr cstr sf__{past_last_slash(__FILE__)}; \
sf__; \
})
#ifndef NO_PRAGMA_MARK
#pragma mark - Tracing Macros -
#endif
#define STRINGPASTE(x) #x
#define TOSTRING(x) STRINGPASTE(x)
#define TRACE() \
({ \
constexpr cstr sf__{past_last_slash(__FILE__ ":" TOSTRING(__LINE__))}; \
sf__; \
})
#define FUNC() __FUNCTION__
#define PRETTY_FUNC() __PRETTY_FUNCTION__
#ifndef NO_PRAGMA_MARK
#pragma mark - Logging Class -
#endif
enum log_level_e
{
off = LOG_LEVEL_OFF,
critical = LOG_LEVEL_CRITICAL,
error = LOG_LEVEL_ERROR,
warning = LOG_LEVEL_WARNING,
info = LOG_LEVEL_INFO,
debug = LOG_LEVEL_DEBUG,
};
class logNames
{
public:
constexpr static const char* level_short_names[LOG_LEVEL_COUNT] = LOG_LEVEL_SHORT_NAMES;
constexpr static const char* level_string_names[LOG_LEVEL_COUNT] = LOG_LEVEL_NAMES;
};
constexpr log_level_e LOG_LEVEL_LIMIT() noexcept
{
return static_cast<log_level_e>(LOG_LEVEL);
}
constexpr const char* LOG_LEVEL_TO_C_STRING(log_level_e level)
{
return logNames::level_string_names[level];
}
constexpr const char* LOG_LEVEL_TO_SHORT_C_STRING(log_level_e level)
{
return logNames::level_short_names[level];
}
class LoggerBase
{
public:
/** Get the current log buffer size
*
* Derived classes must implement this function.
*
* @returns The current size of the log buffer, in bytes.
* The base class returns SIZE_MAX to indicate a potentially invalid condition.
*/
virtual size_t size() const noexcept
{
return SIZE_MAX;
}
/** Get the log buffer capacity
*
* Derived classes must implement this function.
*
* @returns The total capacity of the log buffer, in bytes.
* The base class returns SIZE_MAX to indicate a potentially invalid condition.
*/
virtual size_t capacity() const noexcept
{
return SIZE_MAX;
}
/** Check if the log is enabled.
*
* @returns true if log output is enabled, false if it is disabled.
*/
bool enabled() const noexcept
{
return enabled_;
}
/** Check the echo setting
*
* @returns true if echo to console is enabled, false if disabled.
*/
bool echo() const noexcept
{
return echo_;
}
/** Enable/disable echo to console.
*
* @param en Echo switch. If true, log statements will also be echo'd to the console through
* printf(). If false, log statements will only go to the log buffer.
* @returns The prior value that was configured before the call was made, which allows
* users to restore the previous setting if necessary.
*/
bool echo(bool en) noexcept
{
bool setting = echo_;
echo_ = en;
return setting;
}
/** Get the maximum log level (filtering)
*
* @returns the current log level maximum.
*/
log_level_e level() const noexcept
{
return level_;
}
/** Set the maximum log level (filtering)
*
* @param l The maximum log level. Levels greater than `l` will not be added to the log buffer.
* @returns the current log level maximum.
*/
log_level_e level(log_level_e l) noexcept
{
if(l <= LOG_LEVEL_LIMIT())
{
level_ = l;
}
return level_;
}
/** Enable or disable the auto-flush behavior
*
* If enabled, the log() call will flush the contents of the buffer whenever
* a write is attempted while the buffer is full. If disabled, this will
* not occur. Instead, the user must manually call `flush()` to
*
* @param enabled True enables auto-flush behavior in log(), false disables it.
* When disabled, the user must manually flush() the log buffer contents.
* @returns The auto-flush setting in place prior to this call. This allows
* you to capture the return value, perform some actions, and restore the value
* once you have completed your work.
* @code
* // Disable auto-flush
* bool setting = log.auto_flush(false);
* log.warning(...);
* // Restore previous setting
* log.auto_flush(setting);
* @endcode
*/
bool auto_flush(bool enabled)
{
bool prior = auto_flush_;
auto_flush_ = enabled;
return prior;
}
/** Check whether auto-flush is enabled.
*
* @returns the current auto-flush behavior setting
*/
bool auto_flush()
{
return auto_flush_;
}
/** Check for a buffer overrun condition.
*
* @returns a boolean indicating whether or not an overrun condition has occurred
* since the last time flush() was called. If `true`, this indicates that data
* has been lost from the log buffer.
*/
bool has_overrun()
{
return overrun_occurred_;
}
template<typename... Args>
void critical(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log(log_level_e::critical, fmt, args...);
#else
log(log_level_e::critical, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void critical_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log_interrupt(log_level_e::critical, fmt, args...);
#else
log_interrupt(log_level_e::critical, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void error(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log(log_level_e::error, fmt, args...);
#else
log(log_level_e::error, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void error_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log_interrupt(log_level_e::error, fmt, args...);
#else
log_interrupt(log_level_e::error, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void warning(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log(log_level_e::warning, fmt, args...);
#else
log(log_level_e::warning, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void warning_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log_interrupt(log_level_e::warning, fmt, args...);
#else
log_interrupt(log_level_e::warning, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void info(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log(log_level_e::info, fmt, args...);
#else
log(log_level_e::info, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void info_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log_interrupt(log_level_e::info, fmt, args...);
#else
log_interrupt(log_level_e::info, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void debug(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log(log_level_e::debug, fmt, args...);
#else
log(log_level_e::debug, fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
void debug_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
log_interrupt(log_level_e::debug, fmt, args...);
#else
log_interrupt(log_level_e::debug, fmt, std::forward<const Args>(args)...);
#endif
}
/// Prints directly to the log with no extra characters added to the message.
template<typename... Args>
void print(const Args&... args) noexcept
{
fctprintf(&LoggerBase::log_add_char_to_buffer_bounce, this, args...);
if(echo_)
{
// cppcheck-suppress wrongPrintfScanfArgNum
printf(args...);
}
}
/** Add data to the log buffer from an interrupt context
*
* This call will disable auto-echo and auto-flush behavior for the duration
* of this function call.
*
* @tparam Args Variadic template args. Will be deduced by the compiler. Enables support for
* a variadic function template.
* @param l The log level associated with this statement.
* @param fmt The log format string.
* @param args The variadic arguments that are associated with the format string.
*/
template<typename... Args>
void log_interrupt(log_level_e l, const char* fmt, const Args&... args) noexcept
{
if(enabled_ && l <= level_)
{
bool flush_setting = auto_flush(false);
bool echo_setting = echo(false);
// Add our prefix
print("%s", LOG_LEVEL_TO_SHORT_C_STRING(l));
log_customprefix();
// Send the primary log statement
print(fmt, args...);
// Restore prior settings
auto_flush(flush_setting);
echo(echo_setting);
}
}
/** Add data to the log buffer
*
* @tparam Args Variadic template args. Will be deduced by the compiler. Enables support for
* a variadic function template.
* @param l The log level associated with this statement.
* @param fmt The log format string.
* @param args The variadic arguments that are associated with the format string.
*/
template<typename... Args>
void log(log_level_e l, const char* fmt, const Args&... args) noexcept
{
if(enabled_ && l <= level_)
{
// Add our prefix
print("%s", LOG_LEVEL_TO_SHORT_C_STRING(l));
log_customprefix();
// Send the primary log statement
print(fmt, args...);
}
}
/// Flush the buffered log contents to the target output stream
/// Wrapper for flush_ that resets the overrun_occurred_ flag
/// Can be overridden if desired
virtual void flush() noexcept
{
if(internal_size() > 0)
{
flush_();
if(overrun_occurred_)
{
critical("---Log buffer overrun detected---\n");
flush_();
}
overrun_occurred_ = false;
}
}
/// Clear the contents of the log buffer
/// Wrapper for clear_ that resets the overrun_occurred_ flag
/// Can be overridden if desired
virtual void clear() noexcept
{
overrun_occurred_ = false;
clear_();
}
protected:
/// Default constructor
LoggerBase() = default;
/** Initialize the logger with options
*
* @param enable If true, log statements will be output to the log buffer. If false,
* logging will be disabled and log statements will not be output to the log buffer.
* @param l Runtime log filtering level. Levels greater than the target will not be output
* to the log buffer.
* @param echo If true, log statements will be logged and printed to the console with printf().
* If false, log statements will only be added to the log buffer.
*/
explicit LoggerBase(bool enable, log_level_e l = LOG_LEVEL_LIMIT(),
bool echo = LOG_ECHO_EN_DEFAULT) noexcept
: enabled_(enable), level_(l), echo_(echo)
{
}
/// Default destructor
virtual ~LoggerBase() = default;
/** Flush the buffered log contents to the target output stream
*
* When called, the contents of the internal log buffer will be removed and placed into
* the target output stream.
*
* Outputs can be any target. You will notice many example implementations print
* the log buffer contents to Serial when flush() is called.
*
* Derived classes must implement this function.
*/
virtual void flush_() noexcept {}
/** Clear the contents of the log buffer.
*
* Reset the log buffer to an empty state.
*
* @post The log buffer will be empty.
*/
virtual void clear_() noexcept {}
/** Add a custom prefix to the log file
*
* Define this function in your derived class to supply a custom prefix
* to the log statement. This will appear *after* the log level indicator
* (e.g., <!>), but before the message.
*
* Recommended use of this field might include generating a timestamp:
* <!> [0081838ms] Message goes here.
*
* Derived classes must implement this function.
*/
virtual void log_customprefix() {}
/** Log buffer putc function
*
* This function adds a character to the underlying log buffer.
*
* This function is used with the fctprintf() interface to output to the log buffer.
* This enables the framework to reuse the same print formatting for both logging and printf().
*
* Derived classes must implement this function.
*
* @param c The character to insert into the log buffer.
*/
virtual void log_putc(char c) = 0;
/** Helper function for logging to the buffer.
*
* If auto-flushing is enabled, we check whether the RAM buffer storage
* is full and then call flush(). Otherwise, we forward the character to
* the logging strategy's log_putc() implementation.
*
* Deived classes may override this function if desired.
*
* @param c The character to insert into the log buffer.
*/
virtual void log_add_char_to_buffer(char c)
{
if(internal_size() == internal_capacity())
{
if(auto_flush())
{
flush();
}
else
{
overrun_occurred_ = true;
}
}
log_putc(c);
}
/** putc bounce function
*
* This is a bounce function which registers with the C printf API. We use the private parameter
* to store the `this` pointer so we can get back to our logger's add_char_to_buffer function.
*
* @param c The character to log.
* @param this_ptr The this pointer of the logger instance. Used to invoke log_putc() on the
* correct instance.
*/
static void log_add_char_to_buffer_bounce(char c, void* this_ptr)
{
reinterpret_cast<LoggerBase*>(this_ptr)->log_add_char_to_buffer(c);
}
/** Get the current size of the log buffer internal storage.
*
* This function returns the size of the internal storage, usually a buffer
* or circular buffer in RAM. This buffer size is required for controlling
* auto-flush behavior.
*
* For example, you might store log files on an SD card, but have an
* internal memory representation as well. The SD file size is likely
* much larger than the internal buffer size, so this difference is important.
*
* @returns The current size of the internal staging log buffer, in bytes.
* By default, this returns size(). Override if necessary.
*/
virtual size_t internal_size() const noexcept
{
return size();
}
/** Get the capacity of the log buffer internal storage.
*
* This function returns the capacity of the internal storage, usually a buffer
* or circular buffer in RAM. This buffer size is required for controlling
* auto-flush behavior.
*
* For example, you might store log files on an SD card, but have an
* internal memory representation as well. The SD file capacity is likely
* much larger than the internal buffer capacity, so this difference is important.
*
* @returns The current capacity of the internal staging log buffer, in bytes.
* By default, this returns capacity(). Override if necessary.
*/
virtual size_t internal_capacity() const noexcept
{
return capacity();
}
private:
/// Indicates whether logging is currently enabled
bool enabled_ = LOG_EN_DEFAULT;
/// Indicates whether the library will auto-flush during log() if the buffer
/// is full. If disabled, the user is responsible for coordinating flush() calls.
bool auto_flush_ = LOG_AUTOFLUSH_DEFAULT;
/// Indicates whether an overrun has occurred between flush() calls. If this is `true`,
/// then you know data has been lost.
bool overrun_occurred_ = false;
/// The current log level.
/// Levels greater than the current setting will be filtered out.
log_level_e level_ = LOG_LEVEL_LIMIT();
/// Console echoing.
/// If true, log statements will be printed to the console through printf().
bool echo_ = LOG_ECHO_EN_DEFAULT;
};
/** Declare a static platform logger instance.
*
* This class is used to declare a static platform logger instance.
*
* Define a platform logger which is templated on the log type:
*
* @code
* using PlatformLogger = PlatformLogger_t<CircularLogBufferLogger<8 * 1024>>;
* @endcode
*
* This `PlatformLogger` type will then work with the logging macros (loginfo(), etc.).
*
* The instance can also be grabbed manually:
*
* @code
* PlatformLogger::inst().dump();
* @endcode
*/
template<class TLogger>
class PlatformLogger_t
{
public:
PlatformLogger_t() = default;
~PlatformLogger_t() = default;
static TLogger& inst()
{
static TLogger logger_;
return logger_;
}
template<typename... Args>
inline static void critical(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().critical(fmt, args...);
#else
inst().critical(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void error(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().error(fmt, args...);
#else
inst().error(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void warning(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().warning(fmt, args...);
#else
inst().warning(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void info(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().info(fmt, args...);
#else
inst().info(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void debug(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().debug(fmt, args...);
#else
inst().debug(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void critical_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().critical_interrupt(fmt, args...);
#else
inst().critical_interrupt(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void error_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().error_interrupt(fmt, args...);
#else
inst().error_interrupt(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void warning_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().warning_interrupt(fmt, args...);
#else
inst().warning_interrupt(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void info_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().info_interrupt(fmt, args...);
#else
inst().info_interrupt(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void debug_interrupt(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().debug_interrupt(fmt, args...);
#else
inst().debug_interrupt(fmt, std::forward<const Args>(args)...);
#endif
}
template<typename... Args>
inline static void print(const char* fmt, const Args&... args)
{
#if defined(__AVR__)
inst().print(fmt, args...);
#else
inst().print(fmt, std::forward<const Args>(args)...);
#endif
}
inline static void flush()
{
inst().flush();
}
inline static void clear()
{
inst().clear();
}
inline static log_level_e level(log_level_e l)
{
return inst().level(l);
}
inline static bool echo(bool en)
{
return inst().echo(en);
}
inline static bool auto_flush(bool enabled)
{
return inst().auto_flush(enabled);
}
inline static bool has_overrun()
{
return inst().has_overrun();
}
};
/** @name Logging Macros
*
* The log macros can be overridden by defining them in your platform_logger.h file
*
* Warning is the default log level if one is not supplied
*
* For more information see @ref docs/development/ExtendingTheFramework/customizing_log_macros.md
*
* @{
*/
#if LOG_LEVEL >= LOG_LEVEL_CRITICAL
#ifndef logcritical
#define logcritical(...) PlatformLogger::critical(__VA_ARGS__)
#endif
#else
#define logcritical(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_ERROR
#ifndef logerror
#define logerror(...) PlatformLogger::error(__VA_ARGS__)
#endif
#else
#define logerror(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_WARNING
#ifndef logwarning
#define logwarning(...) PlatformLogger::warning(__VA_ARGS__)
#endif
#else
#define logwarning(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_INFO
#ifndef loginfo
#define loginfo(...) PlatformLogger::info(__VA_ARGS__)
#endif
#else
#define loginfo(...)
#endif
#if LOG_LEVEL >= LOG_LEVEL_DEBUG
#ifndef logdebug
#define logdebug(...) PlatformLogger::debug(__VA_ARGS__)
#endif
#else
#define logdebug(...)
#endif
#define logflush() PlatformLogger::flush();
#define loglevel(lvl) PlatformLogger::level(lvl);
#define logecho(echo) PlatformLogger::echo(lvl);
#define logclear() PlatformLogger::clear();
#endif // ARDUINO_LOGGER_H_