From e3cf9c05e435edd043d18193d19c5b1f73ce2124 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 20 Sep 2023 09:06:54 +0200 Subject: [PATCH] Fix logging macOS process to remove redundant newlines --- Source/Engine/Core/Log.cpp | 4 ++-- Source/Engine/Platform/Mac/MacPlatform.cpp | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Source/Engine/Core/Log.cpp b/Source/Engine/Core/Log.cpp index fea72bfe8..1147c4ff1 100644 --- a/Source/Engine/Core/Log.cpp +++ b/Source/Engine/Core/Log.cpp @@ -223,10 +223,10 @@ void Log::Logger::ProcessLogMessage(LogType type, const StringView& msg, fmt_fla else { //w.append(msg.Get(), msg.Get() + msg.Length()); - fmt_flax::format(w, TEXT("{}"), (const Char*)msg.Get()); + fmt_flax::format(w, TEXT("{}"), msg); } #else - fmt_flax::format(w, TEXT("{}"), (const Char*)msg.Get()); + fmt_flax::format(w, TEXT("{}"), msg); #endif } diff --git a/Source/Engine/Platform/Mac/MacPlatform.cpp b/Source/Engine/Platform/Mac/MacPlatform.cpp index 4c965f549..8f566073f 100644 --- a/Source/Engine/Platform/Mac/MacPlatform.cpp +++ b/Source/Engine/Platform/Mac/MacPlatform.cpp @@ -327,7 +327,7 @@ void MacPlatform::Tick() NSEvent* event = nil; do { - NSEvent* event = [NSApp nextEventMatchingMask: NSEventMaskAny untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES]; + event = [NSApp nextEventMatchingMask: NSEventMaskAny untilDate: nil inMode: NSDefaultRunLoopMode dequeue: YES]; if (event) { [NSApp sendEvent:event]; @@ -464,17 +464,15 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings) } } } - + NSTask *task = [[NSTask alloc] init]; task.launchPath = AppleUtils::ToNSString(exePath); task.arguments = AppleUtils::ParseArguments(AppleUtils::ToNSString(settings.Arguments)); - + if (cwd.Length() != 0) task.currentDirectoryPath = AppleUtils::ToNSString(cwd); - - + int32 returnCode = 0; - if (settings.WaitForEnd) { id outputObserver = nil; @@ -493,11 +491,16 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings) NSData* data = [stdoutPipe fileHandleForReading].availableData; if (data.length) { - String line((char*)data.bytes); + String line((const char*)data.bytes, data.length); if (settings.SaveOutput) settings.Output.Add(line.Get(), line.Length()); if (settings.LogOutput) - Log::Logger::Write(LogType::Info, line); + { + StringView lineView(line); + if (line[line.Length() - 1] == '\n') + lineView = StringView(line.Get(), line.Length() - 1); + Log::Logger::Write(LogType::Info, lineView); + } [[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify]; } }