UE Log Macro Custom 自定義Log封裝
#pragma once
#ifdef _MSC_VER
#define CLASS_FUNCTION FUNCTION
#endif
#ifdef GNUG
#include <cxxabi.h>
#include <execinfo.h>
char *class_func(const char *c, const char *f)
{
int status;
static char buff[100];
char *demangled = abi::__cxa_demangle(c, NULL, NULL, &status);
snprintf(buff, sizeof(buff), “%s::%s”, demangled, f);
free(demangled);
return buff;
}
#define CLASS_FUNCTION class_func(typeid(*this).name(), func)
#endif
/* ClassName::FunctionName where this is called. /
#define CURRENT_CLASS_FUNCTION (FString(CLASS_FUNCTION))
/ Class Name where this is called. /
#define CURRENT_CLASS (FString(CLASS_FUNCTION).Left(FString(CLASS_FUNCTION).Find(TEXT(“:”))) )
/ Function Name where this is called. /
#define CURRENT_FUNCTION (FString(CLASS_FUNCTION).Right(FString(CLASS_FUNCTION).Len() - FString(CLASS_FUNCTION).Find(TEXT(“::”)) - 2 ))
/ Line Number where this is called. /
#define CURRENT_LINE (FString::FromInt(LINE))
/ Class Name and Line Number where this is called. /
#define CURRENT_CLASS_LINE (CURRENT_CLASS + " (" + CURRENT_LINE + “)”)
/ Class Name and Function Name and Line Number where this is called. /
#define CURRENT_CLASS_FUNCTION_LINE (CURRENT_CLASS_FUNCTION + " (" + CURRENT_LINE + “)”)
/ Function Signature where this is called. */
#define CURRENT_FUNCTIONSIG (FString(FUNCSIG))
/*
- UE_LOG macros
*/
/* Equivalent to UE_LOG. /
#define LOG_UE(CategoryName, Verbosity, Message, …) UE_LOG(CategoryName, Verbosity, Message, ##VA_ARGS)
/ Log macro. Style: ClassName::FunctionName Format. */
#define LOG_SENDER(CategoryName, Verbosity, Message, …) UE_LOG(CategoryName, Verbosity, TEXT("%s "), TEXT(CLASS_FUNCTION), Message, ##VA_ARGS )
/* Log macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG(CategoryName, Message) UE_LOG(CategoryName, Log, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, FString(Message))
/ Log macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_PRINTF(CategoryName, FormatString , …) UE_LOG(CategoryName, Log, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
/* Log macro with verbosity. Style: ClassName::FunctionName (Line) Message. */
#define LOG_VERBOSITY(CategoryName, Verbosity, Message) UE_LOG(CategoryName, Verbosity, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, FString(Message))
/ Log macro with verbosity. Style: ClassName::FunctionName (Line) Message. */
#define LOG_VERBOSITY_PRINTF(CategoryName, Verbosity, FormatString , …) UE_LOG(CategoryName, Verbosity, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
/* Log warning macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_WARNING(CategoryName, Message) UE_LOG(CategoryName, Warning, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, FString(Message))
/ Log warning macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_WARNING_PRINTF(CategoryName, FormatString , …) UE_LOG(CategoryName, Warning, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
/* Log error macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_ERROR(CategoryName, Message) UE_LOG(CategoryName, Error, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, FString(Message))
/ Log error macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_ERROR_PRINTF(CategoryName, FormatString , …) UE_LOG(CategoryName, Error, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
#define LOG_ERROR_Format(CategoryName, FormatString , …) UE_LOG(CategoryName, Error, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
/* Log fatal macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_FATAL(CategoryName, Message) UE_LOG(CategoryName, Fatal, TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, FString(Message))
/ Log fatal macro. Style: ClassName::FunctionName (Line) Message. */
#define LOG_FATAL_PRINTF(CategoryName, FormatString , …) UE_LOG(CategoryName,Fatal,TEXT(“%s: %s”), *CURRENT_CLASS_FUNCTION_LINE, *FString::Printf(TEXT(FormatString), ##VA_ARGS ) )
/*
- Screen Messages macros
*/
#define LOG_SCREENMSG(Message) (GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, *(CURRENT_CLASS_FUNCTION_LINE + ": " + Message)) )
#define LOG_SCREENMSG_PRINTF(FormatString , …) (GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, *(CURRENT_CLASS_FUNCTION_LINE + ": " + (FString::Printf(TEXT(FormatString), ##VA_ARGS )))) )