Weird bug in C++: Macros definition for logging

I have created several macroses for easy logging.

The first 2 work fine.
The third brings up a compile error, saying that there should be one more parentheses ‘)’ before ';" when calling the macro.

DEFINITION:

#define LOG_WTF(param1) UE_LOG(LogTemp, Warning, TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString(param1))
#define LOG_WTS(param1) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString(param1)))
#define LOG_WTS2(_formatString, ...) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(_formatString), ##__VA_ARGS__) )

USAGE:

LOG_WTF("This is a warning testLog to file");
LOG_WTS("This is a warning testLog to screen");
LOG_WTS2("This is a warning testLog to screen: LOG_WTS2"));
LOG_WTS2("This is a warning testLog to screen: %s = %d", TEXT("bla"), 123));

Note:
The last two lines are used to call the “LOG_WTS2” macro without and with extra parameters.
If I write the code properly, the compiler tells me to put another ‘)’ before ‘;’ at the end of these two lines.
When I put the extra ‘)’ for each line, the code is compiled and the log is projected correctly to the screen.
It seems like an issue within the definition of macros “LOG_WTS2”.
What is wrong with the code and how can it be fixed?

Update:

After redefining “LOG_WTF” with the same input as “LOG_WTS”, there were no problems with compilation when using the correct syntax, without the extra parentheses ‘)’.

DEFINITION:

#define LOG_WTF(FormatedString, ...) UE_LOG(LogTemp, Warning, TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(FormatedString), ##__VA_ARGS__) )

USAGE:

LOG_WTF("This is a warning testLog to file");
LOG_WTF("This is a warning testLog to file: %s = %d", TEXT("bla"), 123);
LOG_WTS("This is a warning testLog to screen: %s = %d", TEXT("bla"), 123));

Update 2:

When calling “LOG_WTS” from another macro, the compiler still demands using an extra parentheses at the end of macro call:

DEFINITION:

#define LOG_WTA(FormattedString, ...) LOG_WTF(FormattedString, ##__VA_ARGS__) LOG_WTS(FormattedString, ##__VA_ARGS__)

USAGE:

LOG_WTA("This is a warning testLog to WTA: %s = %d", TEXT("bla"), 123));

If you look at the WTS macro, the one that calls AddOnScreenDebugMessage, at the end the first closing ) closes the inner Printf

*FString::Printf(TEXT(_formatString), ##__VA_ARGS__

the second ) closes the outer Printf

FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(_formatString), ##__VA_ARGS__)

which means you never closed the actual function call to AddOnScreenDebugMessage. You need a third ) at the end of that macro to match.