Skip to content

Instantly share code, notes, and snippets.

@PhroZenOne
Last active October 7, 2017 21:19
Show Gist options
  • Save PhroZenOne/a0b0627c07668ce13ae1adb2f1065f62 to your computer and use it in GitHub Desktop.
Save PhroZenOne/a0b0627c07668ce13ae1adb2f1065f62 to your computer and use it in GitHub Desktop.
better version of UE_LOG
#define FUNCTION_NAME_LINE_NR (FString(__FUNCTION__) + TEXT("(") + FString::FromInt(__LINE__) + TEXT(")"))
#ifdef _MSC_VER
#define VALHALLA_LOG(LogCategory, Verbosity, FormatString, ...)\
__if_exists(this)\
{\
if(GEngine->GetWorldFromContextObject(this, EGetWorldErrorMode::ReturnNull))\
{\
switch(GEngine->GetWorldFromContextObject(this, EGetWorldErrorMode::ReturnNull)->GetNetMode())\
{\
case NM_Client:\
UE_LOG(LogCategory,Verbosity,TEXT("%s Client %d: %s"), *FUNCTION_NAME_LINE_NR, (GPlayInEditorID - 1), *FString::Printf(FormatString, ##__VA_ARGS__))\
break;\
case NM_DedicatedServer:\
case NM_ListenServer:\
UE_LOG(LogCategory, Verbosity, TEXT("%s Server: %s"), *FUNCTION_NAME_LINE_NR, *FString::Printf(FormatString, ##__VA_ARGS__))\
break;\
}\
}\
else\
{\
UE_LOG(LogCategory,Verbosity,TEXT("%s %s"), *FUNCTION_NAME_LINE_NR, *FString::Printf(FormatString, ##__VA_ARGS__))\
}\
}\
__if_not_exists(this)\
{\
UE_LOG(LogCategory,Verbosity,TEXT("%s %s"), *FUNCTION_NAME_LINE_NR, *FString::Printf(FormatString, ##__VA_ARGS__))\
}
#else
#define VALHALLA_LOG(LogCategory, Verbosity, FormatString, ...) UE_LOG(LogCategory,Verbosity,TEXT("%s %s"), *FUNCTION_NAME_LINE_NR, *FString::Printf(FormatString, ##__VA_ARGS__))\
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment