How can i get output log information in C++ code?

i’d like to display output log in game, and i read the log file(/Saved/[ProjectName].log) by finding its path

like this:

/// get log fie path
FOutputDevice* OutputDevice = FGenericPlatformOutputDevices::GetLog();
if (OutputDevice != nullptr)
{
OutputDeviceFile = static_cast<FOutputDeviceFile*>(OutputDevice);
LogFile = OutputDeviceFile->GetFilename();
}

OutputDeviceFile->Flush();
if (FFileHelper::LoadFileToString(LogContent, *LogFile, FFileHelper::EHashOptions::None, 4))
{
.....
}

it succeeded but really low performace if i execute it on Tick Event.

i guess it’s due to reading file.

is there any way i can get log information before it has been written to [ProjectName].log

thanks a lot for your help!!!

Don’t need to read the file it’s really redundant. Logging to file is extra feature not the main way log system operates. UE4 let you add custom FOutputDevice to log system and they will recive log data, whatever you do with that log data is up to you at that point.

So first create your own FOutputDevice, look on API refrence so see what you can override:

You can access main log redirector via GLog global object and add your output device with this function

When you do that log system should send you log messages to your output device object

2 Likes