36 lines
1.1 KiB
C++
36 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "CoreMinimal.h"
|
|
#include "Misc/OutputDeviceRedirector.h"
|
|
|
|
class FLogCaptureOutputDevice : public FOutputDevice
|
|
{
|
|
public:
|
|
TArray<FString> CapturedErrors;
|
|
bool bEnabled = true;
|
|
|
|
void Install() { GLog->AddOutputDevice(this); }
|
|
void Uninstall() { GLog->RemoveOutputDevice(this); }
|
|
|
|
// If the device is marked 'CanBeUsedOnMultipleThreads,'
|
|
// then UE_LOG will call Serialize from the current
|
|
// thread, otherwise, it will call Serialize from the
|
|
// logging thread. Without this, we wouldn't be able to
|
|
// tell whether an error is coming from the game thread.
|
|
virtual bool CanBeUsedOnMultipleThreads() const override { return true; }
|
|
|
|
virtual void Serialize(const TCHAR* V, ELogVerbosity::Type Verbosity, const FName& Category) override
|
|
{
|
|
// Only capture messages from the game thread.
|
|
// Other threads generate noise we don't care about.
|
|
if (!IsInGameThread() || !bEnabled) return;
|
|
|
|
if (Verbosity == ELogVerbosity::Warning ||
|
|
Verbosity == ELogVerbosity::Error ||
|
|
Verbosity == ELogVerbosity::Fatal)
|
|
{
|
|
CapturedErrors.Add(FString(V));
|
|
}
|
|
}
|
|
};
|