Log to separate log file

Is it possible to configure Loggers in a way, so a specific (possibly custom) Logger logs into a separate file, instead of the default log file? This way it would be easier to track the log messages of a specific logger, rather then fiddling around with the log levels of all other loggers. Say I want all Loggers of UE to log into the default log file, but all of my own loggers to log into a custom file. I haven’t been able to find any resources online about this.

For logging I simply use the macro UE_LOG(MyLogger, Log, TEXT(“LogMessage”)).

I don’t think there way to do that, but you can set logging levels globally and per log category in ini files (look in below of this page: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums), set global to off and your category to something. It’s not what you want but atleast something

I was afraid that that was the only possibility. Too bad :(. Thanks anyway.

Something I’ve done locally, if it helps, is created a second logger that goes to a different file, and only turned it on when I need to log those particular lines, then removed it after. It’s a bit janky, but it seems to do the job. Example:

void FMyAutomationHelper::LogTestResultsToFile(FOutputDevice * FileToLogTo, FString StatName, FString StatBlob)
{
	GLog->AddOutputDevice(FileToLogTo);

	GLog->Log(TEXT("MyCharPerfTest"), ELogVerbosity::Log, *StatName);
	GLog->Log(TEXT("MyCharPerfTest"), ELogVerbosity::Log, *StatBlob);
	GLog->Flush();
	GLog->RemoveOutputDevice(FileToLogTo);
}

// In use...
	FString FileName = FString::Printf(TEXT("%s_%s_%s.log"), *(FrameData->CharName), *(FrameData->IdentName), *(FString::FromInt(FrameData->IdentValue)));
	FOutputDeviceFile * FileToLogTo = new FOutputDeviceFile(*FileName, false);
	FileToLogTo->SetAutoEmitLineTerminator(true);
FMyAutomationHelper::LogTestResultsToFile(FileToLogTo, TEXT("Timestamps"), *TimestampsAsString);

The file will dump out in /binaries by default, but you can mess around with that!

1 Like

That does the trick. I was forgetting the most important part, to switch activation of the device, then all the logs where flushed to my file. But maybe using standard fstream does the job.