This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.h
51 lines (41 loc) · 1.49 KB
/
Logger.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
#ifndef LOGGER_H
#define LOGGER_H
#include <HardwareSerial.h>
#include "WiFiManager.h"
#include "FilenameMacro.h"
namespace InternalLogger
{
template <typename ...Args>
void Print(const char file[], const int line, const char function[], const Args &...args)
{
Serial.printf("[Log][%s:%d %s()] ", file, line, function);
Serial.print(args...);
}
template <typename ...Args>
void Println(const char file[], const int line, const char function[], const Args &...args)
{
Serial.printf("[Log][%s:%d %s()] ", file, line, function);
Serial.println(args...);
}
template <typename ...Args>
void Printf(const char file[], const int line, const char function[], const Args &...args)
{
Serial.printf("[Log][%s:%d %s()] ", file, line, function);
Serial.printf(args...);
}
template <typename ...Args>
void Throw(const char file[], const int line, const char function[], const Args &...args)
{
Serial.printf("[Error][%s:%d %s()] ", file, line, function);
Serial.printf(args...);
WiFiManager::disconnect();
// Wait until serial messages are sent.
delay(100);
esp_deep_sleep_start();
}
}
#define Print(...) InternalLogger::Print(__FILENAME__, __LINE__, __func__, __VA_ARGS__)
#define Println(...) InternalLogger::Println(__FILENAME__, __LINE__, __func__, __VA_ARGS__)
#define Printf(...) InternalLogger::Printf(__FILENAME__, __LINE__, __func__, __VA_ARGS__)
#define Throw(...) InternalLogger::Throw(__FILENAME__, __LINE__, __func__, __VA_ARGS__)
#endif