#pragma once #include "Engine/Core/Config.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Threading/ThreadLocal.h" #include "Engine/Core/Collections/Array.h" class String; struct Guid; /// /// Log context data structure. Contains different kinds of context data for different situtations. /// API_STRUCT() struct FLAXENGINE_API LogContextData { DECLARE_SCRIPTING_TYPE_STRUCTURE(LogContextData) /// /// A GUID for an object which this context applies to. /// API_FIELD() Guid ObjectID; }; template<> struct TIsPODType { enum { Value = true }; }; /// /// Stores a stack of log contexts. /// API_STRUCT() struct FLAXENGINE_API LogContextStack { DECLARE_SCRIPTING_TYPE_STRUCTURE(LogContextStack) /// /// Log context stack. /// Array Stack; }; template<> struct TIsPODType { enum { Value = true }; }; /// /// Log context interaction class. Methods are thread local, and as such, the context is as well. /// This system is used to pass down important information to be logged through large callstacks /// which don't have any reason to be passing down the information otherwise. /// API_CLASS(Static) class FLAXENGINE_API LogContexts { DECLARE_SCRIPTING_TYPE_MINIMAL(LogContexts) /// /// Adds a log context element to the stack to be displayed in warning and error logs. /// /// The GUID of the object this context applies to. API_FUNCTION() static void Set(const Guid& id); /// /// Pops a log context element off of the stack and discards it. /// API_FUNCTION() static void Clear(); /// /// Gets the log context element off the top of stack. /// /// The log context element at the top of the stack. API_FUNCTION() static LogContextData Get(); private: static ThreadLocal CurrentLogContext; }; /// /// Formatting class which will provide a string to apply /// the current log context to an error or warning. /// API_CLASS(Static) class FLAXENGINE_API LogContextFormatter { DECLARE_SCRIPTING_TYPE_MINIMAL(LogContextFormatter) public: /// /// Returns a string which represents the current log context on the stack. /// /// The formatted string representing the current log context. API_FUNCTION() static String Format(); };