Skip to content

Commit

Permalink
set log level functionality, also better refactoring and blueprint nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
yatima1460 committed Sep 12, 2017
1 parent 5cdf9c9 commit d4097e9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
31 changes: 23 additions & 8 deletions Source/UE4Logger/Private/UE4LoggerBPLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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:
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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



36 changes: 26 additions & 10 deletions Source/UE4Logger/Public/UE4LoggerBPLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Engine/Console.h"
#include "Engine/LocalPlayer.h"
#include "Runtime/Core/Public/Logging/LogVerbosity.h"
#include <LogMacros.h>
#include "UE4LoggerBPLibrary.generated.h"


Expand All @@ -27,32 +28,47 @@
* 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()
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
};
14 changes: 7 additions & 7 deletions UE4Logger.uplugin
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down

0 comments on commit d4097e9

Please sign in to comment.