Last active
April 13, 2024 09:57
-
-
Save Ed94/0ceb523cb714495abbaa50cb64da44e3 to your computer and use it in GitHub Desktop.
UE_LOG but it's not a macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Straight from the Engine | |
| UENUM(BlueprintType) | |
| enum class E<YourModule>Verbosity : uint8 | |
| { | |
| /** Not used */ | |
| NoLogging = 0, | |
| /** Always prints a fatal error to console (and log file) and crashes (even if logging is disabled) */ | |
| //Fatal, | |
| /** | |
| * Prints an error to console (and log file). | |
| * Commandlets and the editor collect and report errors. Error messages result in commandlet failure. | |
| */ | |
| Error = ELogVerbosity::Error, | |
| /** | |
| * Prints a warning to console (and log file). | |
| * Commandlets and the editor collect and report warnings. Warnings can be treated as an error. | |
| */ | |
| Warning, | |
| /** Prints a message to console (and log file) */ | |
| Display, | |
| /** Prints a message to a log file (does not print to console) */ | |
| Log, | |
| /** | |
| * Prints a verbose message to a log file (if Verbose logging is enabled for the given category, | |
| * usually used for detailed logging) | |
| */ | |
| Verbose, | |
| /** | |
| * Prints a verbose message to a log file (if VeryVerbose logging is enabled, | |
| * usually used for detailed logging that would otherwise spam output) | |
| */ | |
| VeryVerbose, | |
| }; | |
| namespace <YourModule> | |
| { | |
| using ELogV = E<YourModule>Verbosity; | |
| //◞ ‸ ◟// | |
| // Works for Unreal 5.4, Win64 MSVC (untested in other scenarios, for now) | |
| inline | |
| void Log( FString Message, E<YourModule>Verbosity Verbosity = EGasaVerbosity::Log | |
| , FLogCategoryBase& Category = <YourDefaultCategory> | |
| , bool DumpStack = false | |
| , int32 Line = __builtin_LINE() | |
| , const ANSICHAR* File = __builtin_FILE() | |
| , const ANSICHAR* Func = __builtin_FUNCTION() ) | |
| { | |
| #if !UE_BUILD_SHIPPING && !NO_LOGGING | |
| ELogVerbosity::Type EngineVerbosity = (ELogVerbosity::Type) Verbosity; | |
| static UE::Logging::Private::FStaticBasicLogDynamicData LOG_Dynamic; | |
| static UE::Logging::Private::FStaticBasicLogRecord | |
| LOG_Static(TEXT("%s -- %hs %hs(%d)"), File, Line, EngineVerbosity, LOG_Dynamic); | |
| // Put the format you like ^^ | |
| if ((EngineVerbosity & ELogVerbosity::VerbosityMask) <= ELogVerbosity::COMPILED_IN_MINIMUM_VERBOSITY) | |
| { | |
| if ((EngineVerbosity & ELogVerbosity::VerbosityMask) <= Category.GetVerbosity()) | |
| { | |
| if ( ! Category.IsSuppressed(EngineVerbosity)) | |
| { | |
| if (DumpStack) | |
| FDebug::DumpStackTraceToLog(EngineVerbosity); | |
| UE::Logging::Private::BasicLog(Category, &LOG_Static, *Message, File, Func, Line); | |
| } | |
| } | |
| } | |
| #endif | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment