From b8d869b800f31fa32fb7828cda8f38cf212b8a08 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 10:56:13 +0100 Subject: [PATCH 01/15] fix: Use an HTTPS URL for the Base submodule --- .gitmodules | 2 +- Base | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitmodules b/.gitmodules index 790311c..e2d6e59 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "Base"] path = Base - url = git@github.com:atalantestudio/ModuleBase + url = https://github.com/atalantestudio/ModuleBase branch = main \ No newline at end of file diff --git a/Base b/Base index e9e0903..3f834f9 160000 --- a/Base +++ b/Base @@ -1 +1 @@ -Subproject commit e9e0903ae85622c84b8d7ce912f783762f6c0f06 +Subproject commit 3f834f97d67902e1e17ca9cc8cc4f11a9fd6c4c7 From cdfaf9e7c886170546d9a1db525e5eeb7a1aa82c Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 11:01:13 +0100 Subject: [PATCH 02/15] fix: Use ATL_ASSERT instead of ASSERT --- scroll/FileLogger/FileLogger.ipp | 2 +- scroll/Logger/Logger.ipp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scroll/FileLogger/FileLogger.ipp b/scroll/FileLogger/FileLogger.ipp index acb72e6..15bda92 100644 --- a/scroll/FileLogger/FileLogger.ipp +++ b/scroll/FileLogger/FileLogger.ipp @@ -6,7 +6,7 @@ namespace scroll { Logger(minLogLevel, source), stream(stream) { - ASSERT(stream.is_open()); + ATL_ASSERT(stream.is_open()); } template diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 1456533..3a0a7ea 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -40,7 +40,7 @@ namespace scroll { } inline void Logger::setArgumentInjectionPattern(view pattern) { - ASSERT(pattern.count() > 0); + ATL_ASSERT(pattern.count() > 0); argumentInjectionPattern = &pattern[0]; } @@ -57,7 +57,7 @@ namespace scroll { // NOTE: std::strftime writes the null-terminating character. sequence hmsString(9); - ASSERT(std::strftime(&hmsString[0], hmsString.count(), "%T", &dateTime) > 0); + ATL_ASSERT(std::strftime(&hmsString[0], hmsString.count(), "%T", &dateTime) > 0); std::ostringstream msStream; msStream << std::setw(3) << std::setfill('0') << ms; From dd0fd81b0530ed82152c6a641b4c453c01fd94dd Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:08:32 +0100 Subject: [PATCH 03/15] fix: Remove Logger::operator<< overload declaration --- scroll/ConsoleLogger/ConsoleLogger.hpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/scroll/ConsoleLogger/ConsoleLogger.hpp b/scroll/ConsoleLogger/ConsoleLogger.hpp index 1c19ca5..2576a71 100644 --- a/scroll/ConsoleLogger/ConsoleLogger.hpp +++ b/scroll/ConsoleLogger/ConsoleLogger.hpp @@ -24,9 +24,6 @@ namespace scroll { template ConsoleLogger& operator<<(Argument&& argument); - template<> - ConsoleLogger& operator<<(ConsoleEscapeCode&& argument); - ConsoleLogger& padLeft(uint64 padding); ConsoleLogger& padRight(uint64 padding); From 16735ca2999c40d330cb01d94b22982c09edb6c5 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:15:05 +0100 Subject: [PATCH 04/15] fix: Use copy utility --- scroll/Logger/Logger.ipp | 6 +++--- scroll/base.hpp | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 3a0a7ea..248182c 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -23,11 +23,11 @@ namespace scroll { sequence updatedPattern(pattern.count() - argumentInjectionPattern.count() + formattedArgument.count()); - std::copy_n(&pattern[0], argumentInjectionPatternOffset, &updatedPattern[0]); - std::copy(formattedArgument.begin(), formattedArgument.end(), &updatedPattern[argumentInjectionPatternOffset]); + copy(&pattern[0], &pattern[argumentInjectionPatternOffset], &updatedPattern[0]); + copy(formattedArgument.begin(), formattedArgument.end(), &updatedPattern[argumentInjectionPatternOffset]); if (argumentInjectionPatternOffset + argumentInjectionPattern.count() < pattern.count()) { - std::copy(&pattern[argumentInjectionPatternOffset + argumentInjectionPattern.count()], pattern.end(), &updatedPattern[argumentInjectionPatternOffset + formattedArgument.count()]); + copy(&pattern[argumentInjectionPatternOffset + argumentInjectionPattern.count()], pattern.end(), &updatedPattern[argumentInjectionPatternOffset + formattedArgument.count()]); } return format(updatedPattern, std::forward(arguments)...); diff --git a/scroll/base.hpp b/scroll/base.hpp index ebf80e4..a986319 100644 --- a/scroll/base.hpp +++ b/scroll/base.hpp @@ -23,4 +23,6 @@ namespace scroll { using atl::sequence; using atl::view; + + using atl::copy; } \ No newline at end of file From 322beae76baedd6debd15c464772f74d57d668c7 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:18:44 +0100 Subject: [PATCH 05/15] fix: Initialize argument injection pattern without C++17 inline --- scroll/Logger/Logger.hpp | 9 ++++++--- scroll/Logger/Logger.ipp | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/scroll/Logger/Logger.hpp b/scroll/Logger/Logger.hpp index 303d5aa..b71bd74 100644 --- a/scroll/Logger/Logger.hpp +++ b/scroll/Logger/Logger.hpp @@ -6,7 +6,12 @@ #include "LogLevel.hpp" namespace scroll { - class Logger { + template + struct ArgumentInjectionPattern { + static sequence argumentInjectionPattern; + }; + + class Logger : public ArgumentInjectionPattern<> { public: // Returns the current argument injection pattern. static view getArgumentInjectionPattern(); @@ -27,8 +32,6 @@ namespace scroll { static void writeIndented(std::ostream& stream, view text, uint64 indentation); private: - static sequence argumentInjectionPattern; - static constexpr uint64 TIMESTAMP_SIZE = 14; static constexpr uint64 MAX_LOG_LEVEL_NAME_SIZE = 7; diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 248182c..a3ceb25 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -2,6 +2,9 @@ // Licensed under MIT. namespace scroll { + template + sequence ArgumentInjectionPattern::argumentInjectionPattern = "[]"; + template sequence Logger::format(Argument&& argument) { std::ostringstream stream; @@ -33,8 +36,6 @@ namespace scroll { return format(updatedPattern, std::forward(arguments)...); } - inline sequence Logger::argumentInjectionPattern = "[]"; - inline view Logger::getArgumentInjectionPattern() { return argumentInjectionPattern; } From 426260211e88cb75bc9b9a9a94c40c2b5d83fb8b Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:23:49 +0100 Subject: [PATCH 06/15] feat: Update Base submodule --- Base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Base b/Base index 3f834f9..367e49e 160000 --- a/Base +++ b/Base @@ -1 +1 @@ -Subproject commit 3f834f97d67902e1e17ca9cc8cc4f11a9fd6c4c7 +Subproject commit 367e49e1c9c47505e82250ee72a61a1154e3a48e From e4d726db1c423e7e09fe333428831688affa4c2a Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:43:20 +0100 Subject: [PATCH 07/15] fix: Colors in cmd.exe --- scroll/ConsoleLogger/ConsoleLogger.ipp | 14 +++++++++++--- scroll/base.hpp | 8 ++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/scroll/ConsoleLogger/ConsoleLogger.ipp b/scroll/ConsoleLogger/ConsoleLogger.ipp index c0572d5..02bdc76 100644 --- a/scroll/ConsoleLogger/ConsoleLogger.ipp +++ b/scroll/ConsoleLogger/ConsoleLogger.ipp @@ -14,9 +14,10 @@ namespace scroll { } inline ConsoleLogger::ConsoleLogger(std::ostream& stream, LogLevel minimumLogLevel, view source) : - Logger(minimumLogLevel, source), - stream(&stream) - {} + Logger(minimumLogLevel, source) + { + setOutputStream(stream); + } inline ConsoleLogger::~ConsoleLogger() { if (writingEscapeCodes) { @@ -30,6 +31,13 @@ namespace scroll { inline void ConsoleLogger::setOutputStream(std::ostream& stream) { this->stream = &stream; + + #if ATL_OPERATING_SYSTEM == ATL_OPERATING_SYSTEM_WINDOWS + const HANDLE hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); + + ATL_ASSERT(hConsoleHandle != NULL && hConsoleHandle != INVALID_HANDLE_VALUE); + ATL_ASSERT(SetConsoleMode(hConsoleHandle, ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING) > 0); + #endif } template diff --git a/scroll/base.hpp b/scroll/base.hpp index a986319..dff1325 100644 --- a/scroll/base.hpp +++ b/scroll/base.hpp @@ -13,6 +13,14 @@ #include "Base/Base/Base.hpp" #endif +#if ATL_OPERATING_SYSTEM == ATL_OPERATING_SYSTEM_WINDOWS + #include + + #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING + #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 + #endif +#endif + namespace scroll { using atl::uint8; using atl::uint16; From c90dfa40ff582c3384db60995deb1fce9d00fb49 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 13:43:38 +0100 Subject: [PATCH 08/15] fix: Include --- scroll/base.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/scroll/base.hpp b/scroll/base.hpp index dff1325..b77f953 100644 --- a/scroll/base.hpp +++ b/scroll/base.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include From 3d82cfda18cb1613c26d03ad15340d1af26d3e0d Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 14:14:35 +0100 Subject: [PATCH 09/15] fix: Use localtime_s on MSVC and std::localtime otherwise --- Base | 2 +- scroll/Logger/Logger.ipp | 17 +++++++++++++---- scroll/base.hpp | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Base b/Base index 367e49e..b2aba16 160000 --- a/Base +++ b/Base @@ -1 +1 @@ -Subproject commit 367e49e1c9c47505e82250ee72a61a1154e3a48e +Subproject commit b2aba16eb2eea4b1a300088e1d37f2b94a3589fd diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index a3ceb25..82cb54a 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -51,15 +51,24 @@ namespace scroll { const uint64 ms = std::chrono::duration_cast(now - std::chrono::time_point_cast(now)).count(); const std::time_t time = std::chrono::system_clock::to_time_t(now); - std::tm dateTime; + std::tm* dateTime; - localtime_s(&dateTime, &time); + #ifdef _MSC_VER + std::tm _dateTime{}; - // NOTE: std::strftime writes the null-terminating character. + ATL_ASSERT(!localtime_s(&_dateTime, &time)); + + dateTime = &_dateTime; + #else + dateTime = std::localtime(&time); + #endif + + // Include null-terminating character. sequence hmsString(9); - ATL_ASSERT(std::strftime(&hmsString[0], hmsString.count(), "%T", &dateTime) > 0); + ATL_ASSERT(std::strftime(&hmsString[0], hmsString.count(), "%H:%M:%S", dateTime) > 0); + // TODO: Reuse the stream. std::ostringstream msStream; msStream << std::setw(3) << std::setfill('0') << ms; diff --git a/scroll/base.hpp b/scroll/base.hpp index b77f953..31607de 100644 --- a/scroll/base.hpp +++ b/scroll/base.hpp @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include From 683582892bcc78cb8711431b1e72c935d171da31 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:07:21 +0100 Subject: [PATCH 10/15] fix: Revert assert expression expansion --- Base | 2 +- scroll/Logger/Logger.ipp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Base b/Base index b2aba16..367e49e 160000 --- a/Base +++ b/Base @@ -1 +1 @@ -Subproject commit b2aba16eb2eea4b1a300088e1d37f2b94a3589fd +Subproject commit 367e49e1c9c47505e82250ee72a61a1154e3a48e diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 82cb54a..adb047b 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -56,7 +56,9 @@ namespace scroll { #ifdef _MSC_VER std::tm _dateTime{}; - ATL_ASSERT(!localtime_s(&_dateTime, &time)); + const errno_t error = localtime_s(&_dateTime, &time); + + ATL_ASSERT(error == 0); dateTime = &_dateTime; #else @@ -66,7 +68,9 @@ namespace scroll { // Include null-terminating character. sequence hmsString(9); - ATL_ASSERT(std::strftime(&hmsString[0], hmsString.count(), "%H:%M:%S", dateTime) > 0); + const uint64 hmsCharacterCount = std::strftime(&hmsString[0], hmsString.count(), "%H:%M:%S", dateTime); + + ATL_ASSERT(hmsCharacterCount > 0); // TODO: Reuse the stream. std::ostringstream msStream; From 08c213efea1738928f6e5f34f4e10cd83a630215 Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:09:19 +0100 Subject: [PATCH 11/15] fix: Include paths relative to / --- scroll/ConsoleLogger/ConsoleLogger.hpp | 8 ++++---- scroll/Conversions.hpp | 4 ++-- scroll/FileLogger/FileLogger.hpp | 6 +++--- scroll/Logger/Logger.hpp | 4 ++-- scroll/scroll.hpp | 10 ++++------ 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scroll/ConsoleLogger/ConsoleLogger.hpp b/scroll/ConsoleLogger/ConsoleLogger.hpp index 2576a71..58925e5 100644 --- a/scroll/ConsoleLogger/ConsoleLogger.hpp +++ b/scroll/ConsoleLogger/ConsoleLogger.hpp @@ -3,9 +3,9 @@ #pragma once -#include "ConsoleEscapeCode.hpp" -#include "Logger/Logger.hpp" -#include "LogLevel.hpp" +#include "scroll/ConsoleEscapeCode.hpp" +#include "scroll/Logger/Logger.hpp" +#include "scroll/LogLevel.hpp" namespace scroll { class ConsoleLogger : public Logger { @@ -64,4 +64,4 @@ namespace scroll { }; } -#include "ConsoleLogger.ipp" \ No newline at end of file +#include "scroll/ConsoleLogger/ConsoleLogger.ipp" \ No newline at end of file diff --git a/scroll/Conversions.hpp b/scroll/Conversions.hpp index 9c54151..cf8565c 100644 --- a/scroll/Conversions.hpp +++ b/scroll/Conversions.hpp @@ -3,11 +3,11 @@ #pragma once -#include "ConsoleEscapeCode.hpp" +#include "scroll/ConsoleEscapeCode.hpp" namespace scroll { std::ostream& operator<<(std::ostream& stream, view view); std::ostream& operator<<(std::ostream& stream, ConsoleEscapeCode code); } -#include "Conversions.ipp" \ No newline at end of file +#include "scroll/Conversions.ipp" \ No newline at end of file diff --git a/scroll/FileLogger/FileLogger.hpp b/scroll/FileLogger/FileLogger.hpp index 945b51d..2daef70 100644 --- a/scroll/FileLogger/FileLogger.hpp +++ b/scroll/FileLogger/FileLogger.hpp @@ -3,8 +3,8 @@ #pragma once -#include "Logger/Logger.hpp" -#include "LogLevel.hpp" +#include "scroll/Logger/Logger.hpp" +#include "scroll/LogLevel.hpp" namespace scroll { class FileLogger : public Logger { @@ -49,4 +49,4 @@ namespace scroll { }; } -#include "FileLogger.ipp" \ No newline at end of file +#include "scroll/FileLogger/FileLogger.ipp" \ No newline at end of file diff --git a/scroll/Logger/Logger.hpp b/scroll/Logger/Logger.hpp index b71bd74..513a59f 100644 --- a/scroll/Logger/Logger.hpp +++ b/scroll/Logger/Logger.hpp @@ -3,7 +3,7 @@ #pragma once -#include "LogLevel.hpp" +#include "scroll/LogLevel.hpp" namespace scroll { template @@ -51,4 +51,4 @@ namespace scroll { }; } -#include "Logger.ipp" \ No newline at end of file +#include "scroll/Logger/Logger.ipp" \ No newline at end of file diff --git a/scroll/scroll.hpp b/scroll/scroll.hpp index 0b0f32a..3e8933a 100644 --- a/scroll/scroll.hpp +++ b/scroll/scroll.hpp @@ -3,9 +3,7 @@ #pragma once -#include "base.hpp" - -#include "Conversions.hpp" - -#include "ConsoleLogger/ConsoleLogger.hpp" -#include "FileLogger/FileLogger.hpp" \ No newline at end of file +#include "scroll/base.hpp" +#include "scroll/Conversions.hpp" +#include "scroll/ConsoleLogger/ConsoleLogger.hpp" +#include "scroll/FileLogger/FileLogger.hpp" \ No newline at end of file From 566ca272b425d8c5df07b303fb346c156978b3dc Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:28:53 +0100 Subject: [PATCH 12/15] feat: Remove \n before stack trace --- scroll/ConsoleLogger/ConsoleLogger.ipp | 8 ++++---- scroll/FileLogger/FileLogger.ipp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/scroll/ConsoleLogger/ConsoleLogger.ipp b/scroll/ConsoleLogger/ConsoleLogger.ipp index 02bdc76..e77eef0 100644 --- a/scroll/ConsoleLogger/ConsoleLogger.ipp +++ b/scroll/ConsoleLogger/ConsoleLogger.ipp @@ -90,7 +90,7 @@ namespace scroll { std::ostream& stream = std::cerr; writeLogHeader(stream, source, "TRACE", ConsoleEscapeCode::BACKGROUND_COLOR_WHITE, ConsoleEscapeCode::FOREGROUND_COLOR_BLACK); - writeIndented(stream, format("[]\nat []:[]", format(std::forward(argument)), file, line), getLogIndentation() - 2); + writeIndented(stream, format("[] (at []:[])", format(std::forward(argument)), file, line), getLogIndentation() - 2); stream << '\n'; } @@ -104,7 +104,7 @@ namespace scroll { std::ostream& stream = std::cerr; writeLogHeader(stream, source, "TRACE", ConsoleEscapeCode::BACKGROUND_COLOR_WHITE, ConsoleEscapeCode::FOREGROUND_COLOR_BLACK); - writeIndented(stream, format("[]\nat []:[]", format(pattern, std::forward(arguments)...), file, line), getLogIndentation() - 2); + writeIndented(stream, format("[] (at []:[])", format(pattern, std::forward(arguments)...), file, line), getLogIndentation() - 2); stream << '\n'; } @@ -203,7 +203,7 @@ namespace scroll { writeLogHeader(stream, source, "ERROR", ConsoleEscapeCode::BACKGROUND_COLOR_LIGHT_RED, ConsoleEscapeCode::FOREGROUND_COLOR_WHITE); stream << "\033[" << ConsoleEscapeCode::FOREGROUND_COLOR_LIGHT_RED << 'm'; - writeIndented(stream, format("[]\nat [] ([]:[])", format(std::forward(argument)), function, file, line), getLogIndentation() - 2); + writeIndented(stream, format("[] (in [], at []:[])", format(std::forward(argument)), function, file, line), getLogIndentation() - 2); stream << "\033[" << ConsoleEscapeCode::RESET_FOREGROUND_COLOR << "m\n"; } @@ -217,7 +217,7 @@ namespace scroll { writeLogHeader(stream, source, "ERROR", ConsoleEscapeCode::BACKGROUND_COLOR_LIGHT_RED, ConsoleEscapeCode::FOREGROUND_COLOR_WHITE); stream << "\033[" << ConsoleEscapeCode::FOREGROUND_COLOR_LIGHT_RED << 'm'; - writeIndented(stream, format("[]\nat [] ([]:[])", format(pattern, std::forward(arguments)...), function, file, line), getLogIndentation() - 2); + writeIndented(stream, format("[] (in [], at []:[])", format(pattern, std::forward(arguments)...), function, file, line), getLogIndentation() - 2); stream << "\033[" << ConsoleEscapeCode::RESET_FOREGROUND_COLOR << "m\n"; } } \ No newline at end of file diff --git a/scroll/FileLogger/FileLogger.ipp b/scroll/FileLogger/FileLogger.ipp index 15bda92..1d5d309 100644 --- a/scroll/FileLogger/FileLogger.ipp +++ b/scroll/FileLogger/FileLogger.ipp @@ -16,7 +16,7 @@ namespace scroll { } writeLogHeader("TRACE"); - writeIndented(stream, format("[]\nat []:[]", format(std::forward(argument)), file, line), getLogIndentation() - 4); + writeIndented(stream, format("[] (at []:[])", format(std::forward(argument)), file, line), getLogIndentation() - 4); stream << '\n'; } @@ -28,7 +28,7 @@ namespace scroll { } writeLogHeader("TRACE"); - writeIndented(stream, format("[]\nat []:[]", format(pattern, std::forward(arguments)...), file, line), getLogIndentation() - 4); + writeIndented(stream, format("[] (at []:[])", format(pattern, std::forward(arguments)...), file, line), getLogIndentation() - 4); stream << '\n'; } @@ -112,7 +112,7 @@ namespace scroll { } writeLogHeader("ERROR"); - writeIndented(stream, format("[]\nat [] ([]:[])", format(std::forward(argument)), function, file, line), getLogIndentation() - 4); + writeIndented(stream, format("[] (in [], at []:[])", format(std::forward(argument)), function, file, line), getLogIndentation() - 4); stream << '\n'; } @@ -124,7 +124,7 @@ namespace scroll { } writeLogHeader("ERROR"); - writeIndented(stream, format("[]\nat [] ([]:[])", format(pattern, std::forward(arguments)...), function, file, line), getLogIndentation() - 4); + writeIndented(stream, format("[] (in [], at []:[])", format(pattern, std::forward(arguments)...), function, file, line), getLogIndentation() - 4); stream << '\n'; } From 1c48904c7c2eb4499680e92ee4b4c1634cdfb59f Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:39:51 +0100 Subject: [PATCH 13/15] feat: Show microseconds in log timestamp --- scroll/Logger/Logger.hpp | 2 +- scroll/Logger/Logger.ipp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scroll/Logger/Logger.hpp b/scroll/Logger/Logger.hpp index 513a59f..1855e86 100644 --- a/scroll/Logger/Logger.hpp +++ b/scroll/Logger/Logger.hpp @@ -32,7 +32,7 @@ namespace scroll { static void writeIndented(std::ostream& stream, view text, uint64 indentation); private: - static constexpr uint64 TIMESTAMP_SIZE = 14; + static constexpr uint64 TIMESTAMP_SIZE = 15; static constexpr uint64 MAX_LOG_LEVEL_NAME_SIZE = 7; public: diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index adb047b..77ca5b9 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -48,7 +48,7 @@ namespace scroll { inline sequence Logger::timestamp() { const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); - const uint64 ms = std::chrono::duration_cast(now - std::chrono::time_point_cast(now)).count(); + const uint64 us = std::chrono::duration_cast(now - std::chrono::time_point_cast(now)).count(); const std::time_t time = std::chrono::system_clock::to_time_t(now); std::tm* dateTime; @@ -73,10 +73,10 @@ namespace scroll { ATL_ASSERT(hmsCharacterCount > 0); // TODO: Reuse the stream. - std::ostringstream msStream; - msStream << std::setw(3) << std::setfill('0') << ms; + std::ostringstream usStream; + usStream << std::setw(6) << std::setfill('0') << us; - return format("[].[]", hmsString, msStream.str()); + return format("[].[]", hmsString, usStream.str()); } inline LogLevel Logger::getMinLogLevel() const { @@ -93,7 +93,7 @@ namespace scroll { {} inline uint16 Logger::getLogIndentation() const { - uint16 indentation = static_cast(TIMESTAMP_SIZE + MAX_LOG_LEVEL_NAME_SIZE + 4); + uint16 indentation = static_cast(1 + TIMESTAMP_SIZE + 3 + MAX_LOG_LEVEL_NAME_SIZE + 2); if (source.count() > 0) { indentation += static_cast(source.count()) + 1; From 485f43861a031f700aa08345fb7b77e94fe6e14e Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:40:30 +0100 Subject: [PATCH 14/15] perf: Use a global string stream to format the log timestamp --- scroll/Logger/Logger.ipp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 77ca5b9..0f3cfb2 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -47,6 +47,8 @@ namespace scroll { } inline sequence Logger::timestamp() { + static std::ostringstream usStream; + const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); const uint64 us = std::chrono::duration_cast(now - std::chrono::time_point_cast(now)).count(); const std::time_t time = std::chrono::system_clock::to_time_t(now); @@ -72,11 +74,13 @@ namespace scroll { ATL_ASSERT(hmsCharacterCount > 0); - // TODO: Reuse the stream. - std::ostringstream usStream; usStream << std::setw(6) << std::setfill('0') << us; - return format("[].[]", hmsString, usStream.str()); + const sequence timestamp = format("[].[]", hmsString, usStream.str()); + + usStream.str({}); + + return timestamp; } inline LogLevel Logger::getMinLogLevel() const { @@ -93,7 +97,7 @@ namespace scroll { {} inline uint16 Logger::getLogIndentation() const { - uint16 indentation = static_cast(1 + TIMESTAMP_SIZE + 3 + MAX_LOG_LEVEL_NAME_SIZE + 2); + uint16 indentation = static_cast(TIMESTAMP_SIZE + MAX_LOG_LEVEL_NAME_SIZE + 6); if (source.count() > 0) { indentation += static_cast(source.count()) + 1; From d8ca32d62e3886eb20b8951da0b226f8a99b82aa Mon Sep 17 00:00:00 2001 From: matteokeole Date: Fri, 21 Nov 2025 15:42:23 +0100 Subject: [PATCH 15/15] perf: Use a global string stream when formatting arguments --- scroll/Logger/Logger.ipp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scroll/Logger/Logger.ipp b/scroll/Logger/Logger.ipp index 0f3cfb2..11be602 100644 --- a/scroll/Logger/Logger.ipp +++ b/scroll/Logger/Logger.ipp @@ -7,11 +7,15 @@ namespace scroll { template sequence Logger::format(Argument&& argument) { - std::ostringstream stream; + static std::ostringstream stream; stream << argument; - return stream.str().c_str(); + const sequence formattedArgument = stream.str().c_str(); + + stream.str({}); + + return formattedArgument; } template