mirror of
https://github.com/HendrikRauh/dmx-interface.git
synced 2025-07-05 13:48:53 +00:00
refactor writeLogEntry: extract serial logging to separate function for improved readability
This commit is contained in:
parent
4f791b72c7
commit
d22c990be1
1 changed files with 9 additions and 1 deletions
10
src/log.cpp
10
src/log.cpp
|
@ -36,8 +36,14 @@ void setupLogger()
|
|||
Serial.println("Logger initialized");
|
||||
}
|
||||
|
||||
void writeSerialLog(const log_level level, const char *tag, const unsigned long timestamp, const char *formattedMessage)
|
||||
{
|
||||
Serial.printf("[%s][%s](%d)> %s\n", getLogLevelString(level), tag, timestamp, formattedMessage);
|
||||
}
|
||||
|
||||
void writeLogEntry(const log_level level, const char *tag, const char *message, ...)
|
||||
{
|
||||
const unsigned long timestamp = millis();
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
int size = vsnprintf(nullptr, 0, message, args);
|
||||
|
@ -46,6 +52,8 @@ void writeLogEntry(const log_level level, const char *tag, const char *message,
|
|||
char *messageBuffer = new char[size + 1];
|
||||
va_start(args, message);
|
||||
vsnprintf(messageBuffer, size + 1, message, args);
|
||||
Serial.printf("[%s][%s](%d)> %s\n", getLogLevelString(level), tag, millis(), messageBuffer);
|
||||
|
||||
writeSerialLog(level, tag, timestamp, messageBuffer);
|
||||
|
||||
delete[] messageBuffer;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue