From 0761036c8caf0e3d1a881529309c2ff09008a03c Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 28 Apr 2022 13:44:39 +0200 Subject: [PATCH] TConsole::StartLoggingToFile: implement --- include/TConsole.h | 1 + src/TConsole.cpp | 16 +++++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/TConsole.h b/include/TConsole.h index 1d64660..839f862 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -39,4 +39,5 @@ private: std::string mStateId; const std::string mDefaultStateId = "BEAMMP_SERVER_CONSOLE"; std::ofstream mLogFileStream; + std::mutex mLogFileStreamMtx; }; diff --git a/src/TConsole.cpp b/src/TConsole.cpp index 1c69791..13e8f2d 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -108,17 +108,11 @@ enum EscState { void TConsole::StartLoggingToFile() { mLogFileStream.open("Server.log"); Application::Console().Internal().on_write = [this](const std::string& ToWrite) { - // sanitize the string by removing all ANSI control codes (like color, etc) - std::string Sanitized; - Sanitized.reserve(ToWrite.size()); - for (size_t i = 0; i < ToWrite.size(); ++i) { - if (i + 1 < ToWrite.size() - && ToWrite[i] == 0x1b) { // starts ANSI escape sequence - if (ToWrite[i + 1] >= 0x40 || ToWrite[i + 1] <= 0x5F) { - } - } - mLogFileStream.write(ToWrite.c_str(), ToWrite.size()); - }; + // TODO: Sanitize by removing all ansi escape codes (vt100) + std::unique_lock Lock(mLogFileStreamMtx); + mLogFileStream.write(ToWrite.c_str(), ToWrite.size()); + mLogFileStream.write("\n", 1); + mLogFileStream.flush(); }; }