1
0
forked from fsfw/fsfw

added colored output for streams as well

This commit is contained in:
2021-01-03 01:35:17 +01:00
parent b30405fee7
commit 0e2875b22d
8 changed files with 52 additions and 38 deletions

View File

@ -1,5 +1,7 @@
#include "../timemanager/Clock.h"
#include "ServiceInterfaceBuffer.h"
#include "serviceInterfaceDefintions.h"
#include <FSFWConfig.h>
#include <cstring>
#include <inttypes.h>
@ -17,6 +19,21 @@ ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string setMessage,
// Set pointers if the stream is buffered.
setp( buf, buf + BUF_SIZE );
}
#if FSFW_COLORED_OUTPUT == 1
if(setMessage.find("DEBUG")) {
colorPrefix = fsfw::ANSI_COLOR_MAGENTA;
}
else if(setMessage.find("INFO")) {
colorPrefix = fsfw::ANSI_COLOR_GREEN;
}
else if(setMessage.find("WARNING")) {
colorPrefix = fsfw::ANSI_COLOR_YELLOW;
}
else if(setMessage.find("ERROR")) {
colorPrefix = fsfw::ANSI_COLOR_RED;
}
#endif
preamble.reserve(MAX_PREAMBLE_SIZE);
preamble.resize(MAX_PREAMBLE_SIZE);
}
@ -102,6 +119,12 @@ std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) {
currentSize += 1;
parsePosition += 1;
}
#if FSFW_COLORED_OUTPUT == 1
currentSize += sprintf(parsePosition, "%s", colorPrefix.c_str());
parsePosition += colorPrefix.size();
#endif
int32_t charCount = sprintf(parsePosition,
"%s: | %02" SCNu32 ":%02" SCNu32 ":%02" SCNu32 ".%03" SCNu32 " | ",
this->logMessage.c_str(), loggerTime.hour,