Passing formatted string to a macro

hello,
I want to be able to write my own logs like this :

MY_LOG(LogDebug, Verbose, (TEXT("Item named %s has spawned"), *Name.ToString()))

and here is my macro:

#define MY_LOG(CategoryName,Verbosity,Message, ...)	
UE_LOG(CategoryName,Verbosity,TEXT("%s [%s]: %s"),*GET_CLASSNAME_WITH_FUNCTION,*GET_LINE_NUMBER,*FString(Message),##__VA_ARGS__)    

i added the “…” and “##VA_ARGS” because i received error that my macro has too many arguments.
the text that gets logged is “Item named %s has spawned” (not formatted with the value)
is there a way to pass a formatted string to the macro? i.e.

auto formattedText= FORMAT(TEXT("Item named %s has spawned"), *Name.ToString())    
 MY_LOG(LogDebug, Verbose,formattedText)

or even make it work like in the first line of code above?

You can actually see exactly what unreal’s log macro is doing in LogMacros.h. You could take that code and do some string manipulation of Format inside your macro to preprend the extra info you want before moving ahead with the rest of the normal logging functionality.

Thank you for replying,
yeah i already tried to dive into the UE_LOG macro but i saw it calls for other methods which were way too complex for me to understand

Well… i didnt find the solution i was hoping for, but for anyone trying to figure out how to save formatted string into variables, i ended up using this:

MY_LOG(LogDebug, Verbose,FString::Printf( TEXT("Actor named %s has spawned"), *Name.ToString()))

You can just do:

UE_LOG(LogTemp, Warning, L"Actor named %s has spawned", *Name.ToString());

Or in your case:

#define MY_LOG(CategoryName,Verbosity,Message, ...) UE_LOG(CategoryName, Verbosity, Message, ##__VA_ARGS__)

MY_LOG(LogDebug, Verbose, L"Actor named %s has spawned", *Name.ToString());