Heres mine.
Theres only one way to call it. It will always go to the screen and log. The reason being there are already perfectly good functions for going straight to log, and writing to screen is a bit of a faff, and if you write to screen with this function you also get a logged copy to review later.
Also I always write code intending for multiplayer, so this version of the log lets me know where it came from… Its all basically a mash up of the wiki and 's suggestion.
#define NETMODE_WORLD (((GEngine == NULL) || (GetWorld() == NULL)) ? TEXT("") \
: (GEngine->GetNetMode(GetWorld()) == NM_Client) ? TEXT("[Client] ") \
: (GEngine->GetNetMode(GetWorld()) == NM_ListenServer) ? TEXT("[ListenServer] ") \
: (GEngine->GetNetMode(GetWorld()) == NM_DedicatedServer) ? TEXT("[DedicatedServer] ") \
: TEXT("[Standalone] "))
#if _MSC_VER
#define CLASS_FUNC_NAME TEXT(__FUNCTION__)
#define CURR_LINE TEXT(__LINE__)
#else // FIXME - GCC?
#define CLASS_FUNC_NAME TEXT(__func__)
#define CURR_LINE TEXT(__line__)
#endif
#define FFLOG(Format, ...) \
{ \
SET_WARN_COLOR( COLOR_CYAN );\
FString Msg = FString::Printf(TEXT(Format), ##__VA_ARGS__ ); \
UE_LOG( LogFF, Log, TEXT("%s%s() : %s"), NETMODE_WORLD, CLASS_FUNC_NAME, *Msg);\
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("%s %s: %s"), NETMODE_WORLD, CLASS_FUNC_NAME, *Msg));\
CLEAR_WARN_COLOR();\
}
#endif
I tried to add the line number from 's code but it kept giving me an error message so I gave up and got on with writing a game