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!!!

The log system is not intended to provide runtime information to the program itself. The user has full control over what log messages are and are not generated.

What are you trying to accomplish, more specifically? If you’re trying to extract some gameplay information, use an in-engine messaging system to get the data to where it needs to go. If you’re trying to provide a log window in-game while paying the game, for visibility, then make an in-memory log sink that you can read yourself. Start lookging at FMsg in LogMacros.h and look at extending the FOutputDevice objects. You can easily wrap your own implementation that makes a copy available on top of the ones that are there.
You really only need to override the Serialize() function in your subclass/proxy class…


UE_LOG(LogTemp, Log, TEXT("Hello world.");

That’s what i want to do! i’d like to create my own messaging system which can get [ProjectName].log in game.

i think override the Serialize() would work! Could you explain it more specifically? i know LogMacros.h is where UE_LOG is, but i never tried to create my subclass of FOutputDevice.

If i created my subclass of FOutputDevice, would it affect the original FOutputDevice? Do i need to create an instance of my FOutputDeivce subclass?

sorry, i’m new to unreal, thanks a lot!

You need to create a subclass of FOutputDevice, and then assign an instance of it as the log device being used. Just trace through the code in the logger, it’s not super complicated.

i did it! it’s really simple! really thanks for your help!