From 141bb1530bd6a83ae4d29486881537e15e76a224 Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Thu, 8 May 2025 14:45:44 +0100 Subject: [PATCH] Improved logger whilst debugger is active --- Common/inc/Logger.h | 8 ++++++++ Lexer/src/Lexer.cpp | 7 +++++-- example/main.lx | 6 ++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Common/inc/Logger.h b/Common/inc/Logger.h index 2193231..d575e19 100644 --- a/Common/inc/Logger.h +++ b/Common/inc/Logger.h @@ -43,6 +43,10 @@ namespace LX // Else prints out the args as provided // else { (*s_LogFile << ... << args); } + + // Flushes the log (only if debugger is attached) // + // Only flushes then as that is when the log is monitered during the process // + if (IsDebuggerPresent()) { s_LogFile->flush(); } } // Variadic template to allow an undefined ammount of arguments // @@ -59,6 +63,10 @@ namespace LX *s_LogFile << '\n' << BREAK << '\n'; (*s_LogFile << ... << args); *s_LogFile << '\n' << BREAK << '\n'; + + // Flushes the log (only if debugger is attached) // + // Only flushes then as that is when the log is monitered during the process // + if (IsDebuggerPresent()) { s_LogFile->flush(); } } // Initalises the log // diff --git a/Lexer/src/Lexer.cpp b/Lexer/src/Lexer.cpp index 59356e3..357f2e2 100644 --- a/Lexer/src/Lexer.cpp +++ b/Lexer/src/Lexer.cpp @@ -245,12 +245,15 @@ namespace LX Log::out("\n"); // Puts a space to clean up the log - for (auto& token : tokens) + for (int i = 0; i < tokens.size(); i++) { + Token& token = tokens[i]; + Log::out ( std::left, - "{ Line: ", std::setw(3), token.line, + "T-Index: ", std::setw(5), i, + " { Line: ", std::setw(3), token.line, ", Index: ", std::setw(3), token.index, ", Length: ", std::setw(2), token.length, " } ", std::setw(30), ToString(token.type) + ":", "{", token.GetContents(), "}" diff --git a/example/main.lx b/example/main.lx index d56ce30..672959f 100644 --- a/example/main.lx +++ b/example/main.lx @@ -1,10 +1,8 @@ func main() { - int a - a = 65465 + int a = 65465 - int b - b = 6 + int b = 6 return a + b }