Skip to content

Commit 29043ec

Browse files
committed
Add helper functions to convert level to strings
Signed-off-by: Jan Losinski <[email protected]>
1 parent 99ab1f9 commit 29043ec

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/ArduinoSimpleLogging.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ void ArduinoSimpleLogging::removeHandler(Print &stream) {
6060
});
6161
}
6262

63+
String ArduinoSimpleLogging::levelToString(ArduinoSimpleLogging::Level level) {
64+
switch (level) {
65+
case ERROR:
66+
return F("error");
67+
case WARNING:
68+
return F("warning");
69+
case INFO:
70+
return F("info");
71+
case DEBUG:
72+
return F("debug");
73+
}
74+
return F("debug");
75+
}
76+
77+
ArduinoSimpleLogging::Level ArduinoSimpleLogging::stringToLevel(
78+
const String &levelName) {
79+
if (levelName.equalsIgnoreCase(F("error"))) {
80+
return ERROR;
81+
} else if (levelName.equalsIgnoreCase(F("warning"))) {
82+
return WARNING;
83+
} else if (levelName.equalsIgnoreCase(F("info"))) {
84+
return INFO;
85+
} else {
86+
return DEBUG;
87+
}
88+
}
89+
6390
ArduinoSimpleLogging Logger;
6491

6592
ArduinoSimpleLogging::LogTarget ArduinoSimpleLogging::debug(DEBUG);

src/ArduinoSimpleLogging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class ArduinoSimpleLogging {
4747
void addHandler(Level level, Print &);
4848
void removeHandler(Print &);
4949

50+
static String levelToString(Level level);
51+
static Level stringToLevel(const String &levelName);
52+
5053
private:
5154
struct LogHandler {
5255
const uint8_t mask;

0 commit comments

Comments
 (0)