core/log: add timestamps to log files

This commit is contained in:
outfoxxed 2024-08-07 13:40:37 -07:00
parent 38ba3fff24
commit 7c7326ec52
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
3 changed files with 25 additions and 5 deletions

View file

@ -21,7 +21,7 @@ void LogManager::messageHandler(
auto* self = LogManager::instance();
LogManager::formatMessage(self->stdoutStream, message, self->colorLogs);
LogManager::formatMessage(self->stdoutStream, message, self->colorLogs, false);
self->stdoutStream << Qt::endl;
emit self->logMessage(message);
@ -32,7 +32,17 @@ LogManager* LogManager::instance() {
return instance;
}
void LogManager::formatMessage(QTextStream& stream, const LogMessage& msg, bool color) {
void LogManager::formatMessage(
QTextStream& stream,
const LogMessage& msg,
bool color,
bool timestamp
) {
if (timestamp) {
if (color) stream << "\033[90m";
stream << msg.time.toString("yyyy-MM-dd hh:mm:ss.zzz");
}
if (color) {
switch (msg.type) {
case QtDebugMsg: stream << "\033[34m DEBUG"; break;
@ -62,4 +72,6 @@ void LogManager::formatMessage(QTextStream& stream, const LogMessage& msg, bool
if (color && msg.type != QtFatalMsg) stream << "\033[0m";
stream << ": " << msg.body;
if (color && msg.type == QtFatalMsg) stream << "\033[0m";
}