LoboMQ
Loading...
Searching...
No Matches
Logger.cpp
Go to the documentation of this file.
1
9#include "Logger.h"
10
11SPIClass spi_logger = SPIClass(VSPI);
12
13Elog *initializeSerialLogger(LoggerClass className, Loglevel level) {
14 Elog *logger = new Elog();
15 const char *serviceName;
16 switch (className) {
17 case BROKER:
18 serviceName = "BROKER";
19 break;
20 case PUBLISHER:
21 serviceName = "PUBLISHER";
22 break;
23 case SUBSCRIBER:
24 serviceName = "SUBSCRIBER";
25 break;
26 default:
27 serviceName = "UNKNOWN";
28 break;
29 }
30 logger->addSerialLogging(Serial, serviceName, level);
31 return logger;
32}
33
34Elog *initializeSDLogger(LoggerClass className, int cs, int sck, int miso, int mosi, Loglevel level) {
35 Elog *logger = new Elog();
36 const char *filepath = "LMQ.log";
37 pinMode(cs, OUTPUT);
38 spi_logger.begin(sck, miso, mosi, cs);
39
40 if (!SD.begin(cs)) {
41 delete logger;
42 logger = initializeSerialLogger(className, level);
43 logger->log(WARNING,
44 "Could not start SD logging, check the SD card pins and the card itself. Logs will be printed to Serial.");
45 } else {
46 logger->configureSd(spi_logger, cs, 2000000);
47 logger->addSdLogging(filepath, level);
48 }
49 return logger;
50}
51
53 //Workaround to disable logging, making it only log the lowest level
54 return initializeSerialLogger(UNKNOWN, EMERGENCY);
55}
Elog * initializeSerialLogger(LoggerClass className, Loglevel level)
Creates a logger that prints messages to the serial monitor.
Definition Logger.cpp:13
Elog * disableLogger()
Creates a logger without the ability to print messages.
Definition Logger.cpp:52
Elog * initializeSDLogger(LoggerClass className, int cs, int sck, int miso, int mosi, Loglevel level)
Creates a logger that prints messages to a file inside a SD card.
Definition Logger.cpp:34
LoggerClass
Enumerates every log class that represents the part of the library which is being logged.
Definition Logger.h:25
@ SUBSCRIBER
Subscriber log class.
Definition Logger.h:31
@ BROKER
Broker log class.
Definition Logger.h:27
@ UNKNOWN
Log class unknown or generic.
Definition Logger.h:33
@ PUBLISHER
Publisher log class.
Definition Logger.h:29