TeensyNanoExoCode
Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1#ifndef LOGGER_H
2#define LOGGER_H
3#include <Arduino.h>
4#include "LogLevels.h"
5#include "Config.h"
6
7#include <functional> // std::bind
8
9namespace logger
10{
18 template <typename T>
19 static void print(T msg, enum LogLevel level = LogLevel::Debug)
20 {
21 // Initialize serial on the first function call, wait for the serial port if the log level is debug
22 static bool has_started{false};
23 if (!has_started)
24 {
25 has_started = true;
26 Serial.begin(logging::baud_rate);
27 }
28 // Only print if the local log level is lower (more important) or equal to the global log level
29 if (level <= logging::level) {
30 Serial.print(msg);
31 }
32 }
33 template <typename T>
34 static void println(T msg = "\n", enum LogLevel level = LogLevel::Debug)
35 {
36 print(String(msg) + "\n", level);
37 }
38 static void println()
39 {
40 println("");
41 }
42}
43#endif
LogLevel
Definition LogLevels.h:5
Definition Logger.h:10
const int baud_rate
Definition Config.h:29
const LogLevel level
Definition Config.h:28