Formatting using a variable as the format specifier

Been banging my head against a wall for hours and I can’t find out what I can do to solve what seems to me a simple issue.

I am making a logging class, and I would like to set it up so each log messages is prefixed with a timestamp. Before suggesting to turn on timestamps in the settings, I want to expand this to print other information later too.

I have the following function:

template <typename FmtType, typename... Types>
static void Info(const FmtType& Fmt, Types... Args)
{
	FString Fmt1 = FString::Printf(TEXT("[%s] %s"), *FDateTime::Now().ToString(), Fmt);
	UE_LOG(LogTemp, Display, *Fmt1, Args...);
}

Which produces the following error:

Severity Code Description Project File Line Suppression
State Error C2338 Formatting string
must be a TCHAR array. Game
D:\Documents\Unreal
Projects\Game\Source\Game\Public\Logger.h 28

When the following line is run:

	Logger::Info(TEXT("World Rotation: %s"), *MouseRotation.ToString());

Essentially what I want to do is change the passed in format string so its slightly different - it adds an additional %s to the beginning so I can print the timestamp as well.

My understanding is that if you dereference a FString, you get a TCHAR. I’ve also tried doing Fmt.GetCharArray() and Fmt.GetCharArray().GetData() and that also has issues. I feel as though I am passing the right arguments and types in, but nothing is working.

Is this even possible? Other things I’ve tried is concatenating TEXT("[%] " to the Fmt that is passed in, no luck. I’ve tried putting a variable into the TEXT() macro, no luck. Not sure what I’m doing wrong or how to do this in a way that works.

I ended up doing things slightly different, after a nights sleep:

template <typename FmtType, typename... Types>
static void Info(const FmtType& Fmt, Types... Args)
{
	FString Message = FString::Printf(Fmt, Args...);
	UE_LOG(LogTemp, Display, TEXT("%s%s"), *GetTimeStamp(), *Message);
}

I guess the bottom line here is Printf accepts a formatted string param variable, created from a TEXT() macro, but UE_LOG does not. So just have to work-around it.