diff --git a/Source/UE4Logger/Private/UE4LoggerBPLibrary.cpp b/Source/UE4Logger/Private/UE4LoggerBPLibrary.cpp index ce6f738..9acc465 100644 --- a/Source/UE4Logger/Private/UE4LoggerBPLibrary.cpp +++ b/Source/UE4Logger/Private/UE4LoggerBPLibrary.cpp @@ -8,8 +8,24 @@ UUE4LoggerBPLibrary::UUE4LoggerBPLibrary(const FObjectInitializer& ObjectInitial } -//utility functions +#pragma region verbosity +void UUE4LoggerBPLibrary::SetLogLevel(UObject * WorldContextObject, ELogLevel eLogLevel) +{ + LogBlueprintUserMessages.SetVerbosity((ELogVerbosity::Type)eLogLevel); +} +ELogLevel UUE4LoggerBPLibrary::GetLogLevel(UObject * WorldContextObject) +{ + return (ELogLevel)LogBlueprintUserMessages.GetVerbosity(); +} + +bool UUE4LoggerBPLibrary::IsLogLevelSuppressed(UObject * WorldContextObject, ELogLevel eLogLevel) +{ + return LogBlueprintUserMessages.IsSuppressed((ELogVerbosity::Type)eLogLevel); +} +#pragma endregion + +#pragma region utility functions void UUE4LoggerBPLibrary::LogInfo(UObject * WorldContextObject, FString InString, bool bPrintToLog, bool bPrintToScreen, float Duration) { UUE4LoggerBPLibrary::Log(WorldContextObject, InString, ELogLevel::Info, bPrintToLog, bPrintToScreen, Duration); @@ -29,13 +45,12 @@ void UUE4LoggerBPLibrary::CrashEngine(UObject * WorldContextObject, FString Mess { UUE4LoggerBPLibrary::Log(WorldContextObject, Message, ELogLevel::Fatal, true, false, 0.0f); } +#pragma endregion -//general function - +#pragma region generic function void UUE4LoggerBPLibrary::Log(UObject* WorldContextObject, FString InString, ELogLevel eLogLevel, bool bPrintToLog, bool bPrintToScreen, float Duration) { FColor logColor = FColor::White; - switch (eLogLevel) { case ELogLevel::Warning: @@ -80,7 +95,6 @@ void UUE4LoggerBPLibrary::Log(UObject* WorldContextObject, FString InString, ELo if (bPrintToLog) { - //can't find a better way of doing this without using a switch because of a strange compiler error switch (eLogLevel) { @@ -106,8 +120,8 @@ void UUE4LoggerBPLibrary::Log(UObject* WorldContextObject, FString InString, ELo } } - // Also output to the screen, if possible - if (bPrintToScreen) + // Also output to the screen if possible and hide suppressed log levels + if (bPrintToScreen && !LogBlueprintUserMessages.IsSuppressed((ELogVerbosity::Type)eLogLevel)) { if (GAreScreenMessagesEnabled) { @@ -122,8 +136,9 @@ void UUE4LoggerBPLibrary::Log(UObject* WorldContextObject, FString InString, ELo UE_LOG(LogBlueprint, Warning, TEXT("Screen messages disabled (!GAreScreenMessagesEnabled). Cannot print to screen.")); } } -} +} +#pragma endregion diff --git a/Source/UE4Logger/Public/UE4LoggerBPLibrary.h b/Source/UE4Logger/Public/UE4LoggerBPLibrary.h index 081c5f3..33232a6 100644 --- a/Source/UE4Logger/Public/UE4LoggerBPLibrary.h +++ b/Source/UE4Logger/Public/UE4LoggerBPLibrary.h @@ -6,6 +6,7 @@ #include "Engine/Console.h" #include "Engine/LocalPlayer.h" #include "Runtime/Core/Public/Logging/LogVerbosity.h" +#include #include "UE4LoggerBPLibrary.generated.h" @@ -27,13 +28,13 @@ * https://wiki.unrealengine.com/Custom_Blueprint_Node_Creation */ -UENUM(BlueprintType) +UENUM(BlueprintType, meta = (Keywords = "UE4logger log level", CompactNodeTitle = "Log Level")) enum ELogLevel { - Info, - Warning, - Error, - Fatal + Fatal = 1, + Error = 2, + Warning = 3, + Info = 5 }; UCLASS() @@ -41,18 +42,33 @@ class UUE4LoggerBPLibrary : public UBlueprintFunctionLibrary { GENERATED_UCLASS_BODY() - UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Info", Keywords = "UE4Logger log info"), Category = "UE4Logger") +#pragma region verbosity + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Set Log Level", Keywords = "UE4Logger log set verbosity level"), Category = "UE4-Logger|Log Level") + static void SetLogLevel(UObject * WorldContextObject, ELogLevel eLogLevel = ELogLevel::Error); + + UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Get Log Level", Keywords = "UE4Logger log get verbosity level"), Category = "UE4-Logger|Log Level") + static ELogLevel GetLogLevel(UObject * WorldContextObject); + + UFUNCTION(BlueprintPure, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Is Log Level Suppressed", Keywords = "UE4Logger log is suppressed verbosity level"), Category = "UE4-Logger|Log Level") + static bool IsLogLevelSuppressed(UObject * WorldContextObject, ELogLevel eLogLevel = ELogLevel::Info); +#pragma endregion + +#pragma region utility functions + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Info", Keywords = "UE4Logger log info print", AdvancedDisplay = "2"), Category = "UE4-Logger") static void LogInfo(UObject* WorldContextObject, FString InString = "Hello", bool bPrintToLog = true, bool bPrintToScreen = true, float Duration = 2.0f); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Warning", Keywords = "UE4Logger log warning"), Category = "UE4Logger") + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Warning", Keywords = "UE4Logger log warning print", AdvancedDisplay = "2"), Category = "UE4-Logger") static void LogWarning(UObject* WorldContextObject, FString InString = "Hello", bool bPrintToLog = true, bool bPrintToScreen = true, float Duration = 2.0f); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Error", Keywords = "UE4Logger log error"), Category = "UE4Logger") + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Error", Keywords = "UE4Logger log error print", AdvancedDisplay = "2"), Category = "UE4-Logger") static void LogError(UObject* WorldContextObject, FString InString = "Hello", bool bPrintToLog = true, bool bPrintToScreen = true, float Duration = 2.0f); - UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Fatal (Crash Engine)", Keywords = "UE4Logger log fatal crash engine"), Category = "UE4Logger|Advanced") + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log Fatal (Crash Engine)", Keywords = "UE4Logger log fatal crash engine print", AdvancedDisplay = "2"), Category = "UE4-Logger|Advanced") static void CrashEngine(UObject* WorldContextObject, FString Message = "Fatal Error"); +#pragma endregion - UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log", Keywords = "UE4Logger log print string"), Category = "UE4Logger") +#pragma region generic function + UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext, DisplayName = "Log", Keywords = "UE4Logger log print string", AdvancedDisplay = "3"), Category = "UE4-Logger") static void Log(UObject* WorldContextObject, FString InString = "Hello", ELogLevel eLogLevel = ELogLevel::Info, bool bPrintToLog = true, bool bPrintToScreen = true, float Duration = 2.0f); +#pragma endregion }; diff --git a/UE4Logger.uplugin b/UE4Logger.uplugin index dcfcf6b..1d350d5 100644 --- a/UE4Logger.uplugin +++ b/UE4Logger.uplugin @@ -1,17 +1,17 @@ { "FileVersion": 3, - "Version": 1, - "VersionName": "0.2", - "FriendlyName": "Advanced Logging", + "Version": 3, + "VersionName": "0.3", + "FriendlyName": "UE4-Logger - Advanced Logging", "Description": "A plugin to add blueprint nodes for a better logging", "Category": "Blueprint", "CreatedBy": "Federico Santamorena", "CreatedByURL": "https://santamorena.me/", - "DocsURL": "https://github.com/Yatima1460/UE4Logger", - "MarketplaceURL": "https://github.com/Yatima1460/UE4Logger", - "SupportURL": "https://github.com/Yatima1460/UE4Logger", + "DocsURL": "https://github.com/Yatima1460/UE4-Logger", + "MarketplaceURL": "https://github.com/Yatima1460/UE4-Logger", + "SupportURL": "https://github.com/Yatima1460/UE4-Logger", "CanContainContent": false, - "IsBetaVersion": true, + "IsBetaVersion": false, "Installed": false, "Modules": [ {