Clear output log?

I know this thread is a bit old, but I’ve figured out a way to clear the output log using C++, it requires some setup though…

in "YourProjectName"Editor.Target.cs file, add “OutputLog” module to public and private dependency names as follows:

.
.
.
		PublicDependencyModuleNames.AddRange(new string[]
		{
			"OutputLog",
		});
		
		PrivateDependencyModuleNames.AddRange(new string[]
		{
			"OutputLog",
		});
.
.
.

Declare a static function in a blueprint function library…

UMyBlueprintFunctionLibrary.h

UCLASS()
class YourProjectName_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

	UFUNCTION(BlueprintCallable)
	static void ClearOutputLog();
}

Now, in the respective .cpp file, it’s important to add the following dependencies:
(otherwise, the UBT will throw linking errors)

#include "OutputLog/Public/OutputLogModule.h"
#include "Developer/OutputLog/Private/SOutputLog.h"
#include "Developer/OutputLog/Private/SOutputLog.cpp"
#include "Developer/OutputLog/Private/OutputLogStyle.h"
#include "Developer/OutputLog/Private/OutputLogStyle.cpp"

Next, implement the static function as follows:

void UMyBlueprintFunctionLibrary::ClearOutputLog()
{
	// Check if the module is loaded before accessing it...
	if (FModuleManager::Get().IsModuleLoaded("OutputLog"))
	{
		const FOutputLogModule& OutputLogModule = FModuleManager::GetModuleChecked< FOutputLogModule >(TEXT("OutputLog"));
		
		// Cast the underlying slate of OutputLogModule to SOutputLog...
		if (const auto OutputLog = StaticCastSharedPtr<SOutputLog>(OutputLogModule.GetOutputLog()); OutputLog.IsValid())
		{
			// Clear the output log...
			if (OutputLog->CanClearLog())
			{
				OutputLog->OnClearLog();
			}
		}
	}
}

That’s all.

You could then call this function in your code or blueprints whenever you want the OutputLog to be cleared.

I hope this helps :slight_smile:

2 Likes