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

View file

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