mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
-40b
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
String getErrorLevelStr(ErrorLevel_t level);
|
#include "Utils/StringUtils.h"
|
||||||
|
|
||||||
class Error : public Printable {
|
class Error : public Printable {
|
||||||
public:
|
public:
|
||||||
@@ -37,7 +37,7 @@ class Error : public Printable {
|
|||||||
|
|
||||||
const String toString() const {
|
const String toString() const {
|
||||||
char buf[128];
|
char buf[128];
|
||||||
sprintf(buf, "[%s] %s", getErrorLevelStr(_level).c_str(), _message);
|
sprintf(buf, "[%c] %s", getErrorLevelStr(_level), _message);
|
||||||
return String(buf);
|
return String(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
#include "Errors.h"
|
#include "Errors.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
|
|
||||||
|
|
||||||
#define pm PrintMessage(MODULE)
|
#define pm PrintMessage(MODULE)
|
||||||
|
|
||||||
class PrintMessage {
|
class PrintMessage {
|
||||||
@@ -24,8 +23,23 @@ class PrintMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
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) {
|
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:
|
private:
|
||||||
|
|||||||
@@ -27,3 +27,5 @@ size_t itemsCount(String str, const String& separator);
|
|||||||
boolean isDigitStr(const String&);
|
boolean isDigitStr(const String&);
|
||||||
|
|
||||||
String prettyBytes(size_t size);
|
String prettyBytes(size_t size);
|
||||||
|
|
||||||
|
const char getErrorLevelStr(uint8_t level);
|
||||||
@@ -111,26 +111,16 @@ String prettyBytes(size_t size) {
|
|||||||
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
return String(size / 1024.0 / 1024.0 / 1024.0) + "GB";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *str_info = "I";
|
const char getErrorLevelStr(uint8_t level) {
|
||||||
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;
|
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case EL_INFO:
|
case EL_INFO:
|
||||||
ptr = str_info;
|
return 'I';
|
||||||
break;
|
|
||||||
case EL_WARNING:
|
case EL_WARNING:
|
||||||
ptr = str_warn;
|
return 'W';
|
||||||
break;
|
|
||||||
case EL_ERROR:
|
case EL_ERROR:
|
||||||
ptr = str_error;
|
return 'E';
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
ptr = str_unknown;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return String(ptr);
|
return '?';
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user