Files
IoTManager/include/Utils/PrintMessage.h

48 lines
934 B
C
Raw Normal View History

2020-09-02 22:34:49 +03:00
#pragma once
#include "Arduino.h"
2020-10-18 09:52:17 +03:00
#include "Utils/StringUtils.h"
#include "Utils/TimeUtils.h"
2020-09-02 22:34:49 +03:00
#include "Errors.h"
#include "Global.h"
#define pm PrintMessage(MODULE)
class PrintMessage {
public:
PrintMessage(const char* module) {
_module = module;
}
void error(const String& str) {
print(EL_ERROR, str);
}
void info(const String& str) {
print(EL_INFO, str);
}
private:
2020-10-18 10:17:24 +03:00
void printErrorLevel(ErrorLevel_t level) {
Serial.printf("[%c] ", getErrorLevelStr(level));
}
void printUptime() {
Serial.printf("%lu ", ((unsigned long)millis() / 1000));
}
void printModule() {
Serial.printf("[%s] ", _module);
}
2020-09-02 22:34:49 +03:00
void print(const ErrorLevel_t level, const String& str) {
2020-10-18 10:17:24 +03:00
printUptime();
printErrorLevel(level);
printModule();
Serial.println(str.c_str());
2020-09-02 22:34:49 +03:00
}
private:
const char* _module;
};