Logger: add an indent level system.

This will help when I'll re-add printing for property types.
This commit is contained in:
Guillaume Jacquemin 2022-04-29 17:19:27 +02:00
parent 98cb314725
commit 2d1d46ec08
2 changed files with 25 additions and 2 deletions

View File

@ -24,6 +24,8 @@
#include <Corrade/Containers/GrowableArray.h>
#include <Corrade/Utility/Debug.h>
#include <Magnum/Types.h>
#include "Logger.h"
using Containers::Array;
@ -31,12 +33,16 @@ using Utility::Debug;
using Utility::Warning;
using Utility::Error;
using namespace Magnum;
namespace MassBuilderSaveTool { namespace Logger {
#ifndef SAVETOOL_DEBUG_BUILD
static std::ofstream log_file{"SaveToolLog.txt", std::ios::trunc};
#endif
static UnsignedInt _indentLevel = 0;
static std::mutex _logMutex;
static Array<LogEntry> _entries;
@ -70,6 +76,10 @@ operator<<(Debug& out, const LogEntry& entry) {
#undef DEBUG_COLOUR
for(UnsignedInt i = 0; i < _indentLevel; i++) {
out << Debug::nospace << " "_s << Debug::nospace;
}
out << entry.message << Debug::resetColor;
return out;
@ -80,6 +90,18 @@ initialise() {
arrayReserve(_entries, 100);
}
void
indent() {
_indentLevel++;
}
void
unindent() {
if(_indentLevel > 0) {
_indentLevel--;
}
}
void
addEntry(EntryType type, StringView message) {
auto time = std::time(nullptr);

View File

@ -44,14 +44,15 @@ struct LogEntry {
void initialise();
void indent();
void unindent();
void addEntry(EntryType type, StringView message);
auto entries() -> ArrayView<const LogEntry>;
void lockMutex();
void unlockMutex();
bool tryLockMutex();
} // Logger