This commit is contained in:
Yuri Trikoz
2020-10-18 10:17:24 +03:00
parent 281f338f97
commit 8778de1ffd
4 changed files with 26 additions and 20 deletions

View File

@@ -2,7 +2,7 @@
#include <Arduino.h>
String getErrorLevelStr(ErrorLevel_t level);
#include "Utils/StringUtils.h"
class Error : public Printable {
public:
@@ -37,7 +37,7 @@ class Error : public Printable {
const String toString() const {
char buf[128];
sprintf(buf, "[%s] %s", getErrorLevelStr(_level).c_str(), _message);
sprintf(buf, "[%c] %s", getErrorLevelStr(_level), _message);
return String(buf);
}

View File

@@ -6,7 +6,6 @@
#include "Errors.h"
#include "Global.h"
#define pm PrintMessage(MODULE)
class PrintMessage {
@@ -24,8 +23,23 @@ class PrintMessage {
}
private:
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);
}
void print(const ErrorLevel_t level, const String& str) {
Serial.printf("%s [%s] [%s] %s\n", prettyMillis(millis()).c_str(), getErrorLevelStr(level).c_str(), _module, str.c_str());
printUptime();
printErrorLevel(level);
printModule();
Serial.println(str.c_str());
}
private:

View File

@@ -26,4 +26,6 @@ size_t itemsCount(String str, const String& separator);
boolean isDigitStr(const String&);
String prettyBytes(size_t size);
String prettyBytes(size_t size);
const char getErrorLevelStr(uint8_t level);

View File

@@ -111,26 +111,16 @@ String prettyBytes(size_t size) {
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
}
static const char *str_info = "I";
static const char *str_warn = "W";
static const char *str_error = "E";
static const char *str_unknown = "?";
String getErrorLevelStr(ErrorLevel_t level) {
const char *ptr;
const char getErrorLevelStr(uint8_t level) {
switch (level) {
case EL_INFO:
ptr = str_info;
break;
return 'I';
case EL_WARNING:
ptr = str_warn;
break;
return 'W';
case EL_ERROR:
ptr = str_error;
break;
return 'E';
default:
ptr = str_unknown;
break;
}
return String(ptr);
return '?';
}