Add support for building engine without logging
This commit is contained in:
@@ -174,7 +174,9 @@ void EditorAnalytics::StartSession()
|
||||
// Bind events
|
||||
GameCooker::OnEvent.Bind<RegisterGameCookingStart>();
|
||||
ShadowsOfMordor::Builder::Instance()->OnBuildStarted.Bind<RegisterLightmapsBuildingStart>();
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::OnError.Bind<RegisterError>();
|
||||
#endif
|
||||
}
|
||||
|
||||
void EditorAnalytics::EndSession()
|
||||
@@ -187,7 +189,9 @@ void EditorAnalytics::EndSession()
|
||||
// Unbind events
|
||||
GameCooker::OnEvent.Unbind<RegisterGameCookingStart>();
|
||||
ShadowsOfMordor::Builder::Instance()->OnBuildStarted.Unbind<RegisterLightmapsBuildingStart>();
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::OnError.Unbind<RegisterError>();
|
||||
#endif
|
||||
|
||||
// End session
|
||||
{
|
||||
|
||||
@@ -156,7 +156,9 @@ ManagedEditor::ManagedEditor()
|
||||
lightmapsBuilder->OnBuildProgress.Bind<OnLightmapsBuildProgress>();
|
||||
lightmapsBuilder->OnBuildFinished.Bind<OnLightmapsBuildFinished>();
|
||||
CSG::Builder::OnBrushModified.Bind<OnBrushModified>();
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::OnMessage.Bind<OnLogMessage>();
|
||||
#endif
|
||||
VisualScripting::DebugFlow.Bind<OnVisualScriptingDebugFlow>();
|
||||
}
|
||||
|
||||
@@ -172,7 +174,9 @@ ManagedEditor::~ManagedEditor()
|
||||
lightmapsBuilder->OnBuildProgress.Unbind<OnLightmapsBuildProgress>();
|
||||
lightmapsBuilder->OnBuildFinished.Unbind<OnLightmapsBuildFinished>();
|
||||
CSG::Builder::OnBrushModified.Unbind<OnBrushModified>();
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::OnMessage.Unbind<OnLogMessage>();
|
||||
#endif
|
||||
VisualScripting::DebugFlow.Unbind<OnVisualScriptingDebugFlow>();
|
||||
}
|
||||
|
||||
|
||||
@@ -38,10 +38,12 @@ namespace
|
||||
|
||||
void PrintStack(LogType type)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
const String stack = VisualScripting::GetStackTrace();
|
||||
Log::Logger::Write(type, TEXT("Visual Script stack trace:"));
|
||||
Log::Logger::Write(type, stack);
|
||||
Log::Logger::Write(type, TEXT(""));
|
||||
#endif
|
||||
}
|
||||
|
||||
bool SerializeValue(const Variant& a, const Variant& b)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "Log.h"
|
||||
#if LOG_ENABLE
|
||||
#include "Engine/Engine/CommandLine.h"
|
||||
#include "Engine/Core/Types/DateTime.h"
|
||||
#include "Engine/Core/Collections/Array.h"
|
||||
@@ -310,3 +311,5 @@ const Char* ToString(LogType e)
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,27 +7,6 @@
|
||||
#include "Engine/Core/Types/String.h"
|
||||
#include "Engine/Core/Types/StringView.h"
|
||||
|
||||
// Enable/disable auto flush function
|
||||
#define LOG_ENABLE_AUTO_FLUSH 1
|
||||
|
||||
/// <summary>
|
||||
/// Sends a formatted message to the log file (message type - describes level of the log (see LogType enum))
|
||||
/// </summary>
|
||||
#define LOG(messageType, format, ...) Log::Logger::Write(LogType::messageType, ::String::Format(TEXT(format), ##__VA_ARGS__))
|
||||
|
||||
/// <summary>
|
||||
/// Sends a string message to the log file (message type - describes level of the log (see LogType enum))
|
||||
/// </summary>
|
||||
#define LOG_STR(messageType, str) Log::Logger::Write(LogType::messageType, str)
|
||||
|
||||
#if LOG_ENABLE_AUTO_FLUSH
|
||||
// Noop as log is auto-flushed on write
|
||||
#define LOG_FLUSH()
|
||||
#else
|
||||
// Flushes the log file buffer
|
||||
#define LOG_FLUSH() Log::Logger::Flush()
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// The log message types.
|
||||
/// </summary>
|
||||
@@ -54,6 +33,29 @@ API_ENUM() enum class LogType
|
||||
Fatal = 8,
|
||||
};
|
||||
|
||||
#if LOG_ENABLE
|
||||
|
||||
// Enable/disable auto flush function
|
||||
#define LOG_ENABLE_AUTO_FLUSH 1
|
||||
|
||||
/// <summary>
|
||||
/// Sends a formatted message to the log file (message type - describes level of the log (see LogType enum))
|
||||
/// </summary>
|
||||
#define LOG(messageType, format, ...) Log::Logger::Write(LogType::messageType, ::String::Format(TEXT(format), ##__VA_ARGS__))
|
||||
|
||||
/// <summary>
|
||||
/// Sends a string message to the log file (message type - describes level of the log (see LogType enum))
|
||||
/// </summary>
|
||||
#define LOG_STR(messageType, str) Log::Logger::Write(LogType::messageType, str)
|
||||
|
||||
#if LOG_ENABLE_AUTO_FLUSH
|
||||
// Noop as log is auto-flushed on write
|
||||
#define LOG_FLUSH()
|
||||
#else
|
||||
// Flushes the log file buffer
|
||||
#define LOG_FLUSH() Log::Logger::Flush()
|
||||
#endif
|
||||
|
||||
extern const Char* ToString(LogType e);
|
||||
|
||||
namespace Log
|
||||
@@ -186,3 +188,11 @@ namespace Log
|
||||
static void ProcessLogMessage(LogType type, const StringView& msg, fmt_flax::memory_buffer& w);
|
||||
};
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define LOG(messageType, format, ...)
|
||||
#define LOG_STR(messageType, str)
|
||||
#define LOG_FLUSH()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -47,6 +47,7 @@ ThreadLocal<LogContextThreadData> GlobalLogContexts;
|
||||
|
||||
void LogContext::Print(LogType verbosity)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
auto& stack = GlobalLogContexts.Get();
|
||||
if (stack.Count == 0)
|
||||
return;
|
||||
@@ -102,6 +103,7 @@ void LogContext::Print(LogType verbosity)
|
||||
// Print message
|
||||
Log::Logger::Write(verbosity, msg.ToStringView());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void LogContext::Push(const Guid& id)
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
Log::Exception::~Exception()
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
// Always write exception to the log
|
||||
Logger::Write(_level, ToString());
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -150,7 +150,9 @@ int32 Engine::Main(const Char* cmdLine)
|
||||
{
|
||||
// End
|
||||
LOG(Warning, "Loading project cancelled. Closing...");
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::Dispose();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -168,8 +170,10 @@ int32 Engine::Main(const Char* cmdLine)
|
||||
#if !USE_EDITOR && (PLATFORM_WINDOWS || PLATFORM_LINUX || PLATFORM_MAC)
|
||||
EngineImpl::RunInBackground = PlatformSettings::Get()->RunInBackground;
|
||||
#endif
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::WriteFloor();
|
||||
LOG_FLUSH();
|
||||
#endif
|
||||
Time::Synchronize();
|
||||
EngineImpl::IsReady = true;
|
||||
PROFILE_MEM_END();
|
||||
@@ -546,14 +550,17 @@ void Engine::OnExit()
|
||||
ProfilerGPU::Dispose();
|
||||
#endif
|
||||
|
||||
#if LOG_ENABLE
|
||||
// Close logging service
|
||||
Log::Logger::Dispose();
|
||||
#endif
|
||||
|
||||
Platform::Exit();
|
||||
}
|
||||
|
||||
void EngineImpl::InitLog()
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
// Initialize logger
|
||||
Log::Logger::Init();
|
||||
|
||||
@@ -607,6 +614,7 @@ void EngineImpl::InitLog()
|
||||
Platform::LogInfo();
|
||||
|
||||
LOG_FLUSH();
|
||||
#endif
|
||||
}
|
||||
|
||||
void EngineImpl::InitPaths()
|
||||
|
||||
@@ -101,8 +101,10 @@ bool GraphicsService::Init()
|
||||
PROFILE_MEM(Graphics);
|
||||
|
||||
// Create and initialize graphics device
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::WriteFloor();
|
||||
LOG(Info, "Creating Graphics Device...");
|
||||
#endif
|
||||
PixelFormatExtensions::Init();
|
||||
GPUDevice* device = nullptr;
|
||||
|
||||
@@ -216,7 +218,9 @@ bool GraphicsService::Init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::WriteFloor();
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -250,8 +250,10 @@ void RenderToolsVulkan::LogVkResult(VkResult result, const char* file, uint32 li
|
||||
errorType = FatalErrorType::GPUCrash;
|
||||
if (errorType != FatalErrorType::None)
|
||||
Platform::Fatal(msg, nullptr, errorType);
|
||||
#if LOG_ENABLE
|
||||
else
|
||||
Log::Logger::Write(fatal ? LogType::Fatal : LogType::Error, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool RenderToolsVulkan::HasExtension(const Array<const char*>& extensions, const char* name)
|
||||
|
||||
@@ -310,6 +310,7 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
||||
Engine::RequestingExit();
|
||||
|
||||
// Collect crash info (platform-dependant implementation that might collect stack trace and/or create memory dump)
|
||||
#if LOG_ENABLE
|
||||
{
|
||||
// Log separation for crash info
|
||||
LOG_FLUSH();
|
||||
@@ -406,6 +407,7 @@ void PlatformBase::Fatal(const StringView& msg, void* context, FatalErrorType er
|
||||
LOG(Error, "Crash info collected.");
|
||||
Log::Logger::WriteFloor();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Show error message
|
||||
if (Engine::ReportCrash.IsBinded())
|
||||
|
||||
@@ -490,7 +490,9 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
|
||||
StringView lineView(line);
|
||||
if (line[line.Length() - 1] == '\n')
|
||||
lineView = StringView(line.Get(), line.Length() - 1);
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::Write(LogType::Info, lineView);
|
||||
#endif
|
||||
}
|
||||
[[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
||||
}
|
||||
@@ -517,7 +519,9 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
|
||||
StringView lineView(line);
|
||||
if (line[line.Length() - 1] == '\n')
|
||||
lineView = StringView(line.Get(), line.Length() - 1);
|
||||
#if LOG_ENABLE
|
||||
Log::Logger::Write(LogType::Error, lineView);
|
||||
#endif
|
||||
}
|
||||
[[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
|
||||
}
|
||||
|
||||
@@ -394,6 +394,7 @@ ProfilerMemory::GroupsArray ProfilerMemory::GetGroups(int32 mode)
|
||||
|
||||
void ProfilerMemory::Dump(const StringView& options)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
bool file = options.Contains(TEXT("file"));
|
||||
StringBuilder output;
|
||||
int32 maxCount = 20;
|
||||
@@ -408,6 +409,7 @@ void ProfilerMemory::Dump(const StringView& options)
|
||||
return;
|
||||
}
|
||||
LOG_STR(Info, output.ToStringView());
|
||||
#endif
|
||||
}
|
||||
|
||||
void ProfilerMemory::OnMemoryAlloc(void* ptr, uint64 size)
|
||||
|
||||
@@ -52,13 +52,16 @@ DEFINE_INTERNAL_CALL(int32) PlatformInternal_MemoryCompare(const void* buf1, con
|
||||
|
||||
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_LogWrite(LogType level, MString* msgObj)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
StringView msg;
|
||||
MUtils::ToString(msgObj, msg);
|
||||
Log::Logger::Write(level, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_Log(LogType level, MString* msgObj, ScriptingObject* obj, MString* stackTrace)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
if (msgObj == nullptr)
|
||||
return;
|
||||
|
||||
@@ -71,6 +74,7 @@ DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_Log(LogType level, MString* m
|
||||
// TODO: maybe option for build to threat warnings and errors as fatal errors?
|
||||
//const String logMessage = String::Format(TEXT("Debug:{1} {2}"), objName, *msg);
|
||||
Log::Logger::Write(level, msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_INTERNAL_CALL(void) DebugLogHandlerInternal_LogException(MObject* exception, ScriptingObject* obj)
|
||||
|
||||
@@ -246,6 +246,7 @@ MType* MEvent::GetType() const
|
||||
|
||||
void MException::Log(const LogType type, const Char* target)
|
||||
{
|
||||
#if LOG_ENABLE
|
||||
// Log inner exceptions chain
|
||||
MException* inner = InnerException;
|
||||
while (inner)
|
||||
@@ -260,6 +261,7 @@ void MException::Log(const LogType type, const Char* target)
|
||||
const String info = target && *target ? String::Format(TEXT("Exception has been thrown during {0}."), target) : TEXT("Exception has been thrown.");
|
||||
Log::Logger::Write(LogType::Warning, String::Format(TEXT("{0} {1}\nStack strace:\n{2}"), info, Message, stackTrace));
|
||||
Log::Logger::Write(type, String::Format(TEXT("{0}\n{1}"), info, Message));
|
||||
#endif
|
||||
}
|
||||
|
||||
MType* MProperty::GetType() const
|
||||
|
||||
Reference in New Issue
Block a user