Skip to content

Instantly share code, notes, and snippets.

@dgavedissian
Last active May 24, 2022 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgavedissian/cdd3873bfc59ba418be77588d648db36 to your computer and use it in GitHub Desktop.
Save dgavedissian/cdd3873bfc59ba418be77588d648db36 to your computer and use it in GitHub Desktop.
UE4 SpatialOS output device
#include "SpatialOutputDevice.h"
FSpatialOutputDevice::FSpatialOutputDevice(USpatialOS* SpatialOSInstance, FString LoggerName)
{
SpatialOS = SpatialOSInstance;
Name = LoggerName;
FilterLevel = ELogVerbosity::All;
FOutputDeviceRedirector::Get()->AddOutputDevice(this);
}
FSpatialOutputDevice::~FSpatialOutputDevice()
{
FOutputDeviceRedirector::Get()->RemoveOutputDevice(this);
}
void FSpatialOutputDevice::Serialize(const TCHAR* InData, ELogVerbosity::Type Verbosity, const class FName& Category)
{
if (Verbosity > FilterLevel || !CategoriesToRedirect.Contains(Category) || !IsValid(SpatialOS))
{
return;
}
TSharedPtr<worker::Connection> Connection = SpatialOS->GetConnection().Pin();
if (Connection.IsValid())
{
Connection->SendLogMessage(ConvertLogLevelToSpatial(Verbosity), TCHAR_TO_UTF8(*Name), TCHAR_TO_UTF8(InData));
}
}
void FSpatialOutputDevice::AddRedirectCategory(const FName& Category)
{
CategoriesToRedirect.Add(Category);
}
void FSpatialOutputDevice::RemoveRedirectCategory(const FName& Category)
{
CategoriesToRedirect.Remove(Category);
}
void FSpatialOutputDevice::SetVerbosityFilterLevel(ELogVerbosity::Type Verbosity)
{
FilterLevel = Verbosity;
}
worker::LogLevel FSpatialOutputDevice::ConvertLogLevelToSpatial(ELogVerbosity::Type Verbosity)
{
switch (Verbosity)
{
case ELogVerbosity::Fatal:
return worker::LogLevel::kFatal;
case ELogVerbosity::Error:
return worker::LogLevel::kError;
case ELogVerbosity::Warning:
return worker::LogLevel::kWarn;
default:
return worker::LogLevel::kInfo;
}
}
#pragma once
#include "CoreMinimal.h"
#include "Misc/OutputDevice.h"
#include "SpatialOS.h"
class YOUR_PROJECT_API FSpatialOutputDevice : public FOutputDevice
{
public:
FSpatialOutputDevice(USpatialOS* SpatialOSInstance, FString LoggerName);
~FSpatialOutputDevice();
void AddRedirectCategory(const FName& Category);
void RemoveRedirectCategory(const FName& Category);
void SetVerbosityFilterLevel(ELogVerbosity::Type Verbosity);
void Serialize(const TCHAR* InData, ELogVerbosity::Type Verbosity, const FName& Category) override;
static worker::LogLevel ConvertLogLevelToSpatial(ELogVerbosity::Type Verbosity);
protected:
ELogVerbosity::Type FilterLevel;
TSet<FName> CategoriesToRedirect;
USpatialOS* SpatialOS;
FString Name;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment