UE427_Logging
UE_LOG宏会经常用到,方便地判断我们的代码何时能够起到作用。
#define UE_LOG(CategoryName, Verbosity, Format, ...)
它的前两个参数表示日志的类别名称(可以随意命名)以及日志的级别(ELogVerbosity枚举量),之后的参数类似于经典的printf(),但是最常用的参数类型只有%d(整数),%f(浮点数)和%s(字符串,并且一定是FString类型),我们需要执行必要的转换函数将char*转换到FString再输入到日志中。
namespace ELogVerbosity
{
enum Type : uint8;
}
namespace ELogVerbosity
{
enum Type : uint8
{
/** Not used */
NoLogging = 0,
/** Always prints a fatal error to console (and log file) and crashes (even if logging is disabled) */
Fatal,
/**
* Prints an error to console (and log file).
* Commandlets and the editor collect and report errors. Error messages result in commandlet failure.
*/
Error,
/**
* Prints a warning to console (and log file).
* Commandlets and the editor collect and report warnings. Warnings can be treated as an error.
*/
Warning,
/** Prints a message to console (and log file) */
Display,
/** Prints a message to a log file (does not print to console) */
Log,
/**
* Prints a verbose message to a log file (if Verbose logging is enabled for the given category,
* usually used for detailed logging)
*/
Verbose,
/**
* Prints a verbose message to a log file (if VeryVerbose logging is enabled,
* usually used for detailed logging that would otherwise spam output)
*/
VeryVerbose,
// Log masks and special Enum values
All = VeryVerbose,
NumVerbosity,
VerbosityMask = 0xf,
SetColor = 0x40, // not actually a verbosity, used to set the color of an output device
BreakOnLog = 0x80
};
}
// Log格式:
// 1. Log Message
//"This is a message to yourself during runtime!"
UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));
// 2. Log an FString
// %s strings are wanted as TCHAR* by Log, so use *FString() %s字符串被日志需要作为TCHAR*,所以使用*FString()
//"MyCharacter's Name is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );
// 3. Log an Int
//"MyCharacter's Health is %d"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );
// 4. Log a Float
//"MyCharacter's Health is %f"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );
// 5. Log an FVector
//"MyCharacter's Location is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"),
*MyCharacter->GetActorLocation().ToString());
// 6. Log an FName
//"MyCharacter's FName is %s"
UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"),
*MyCharacter->GetFName().ToString());
// 7. Log an FString,Int,Float
//"%s has health %d, which is %f percent of total health" %s的生命值%d,也就是总生命值的%f %
UE_LOG(YourLog,Warning,TEXT("%s has health %d, which is %f percent of total health"),
*MyCharacter->GetName(), MyCharacter->Health, MyCharacter->HealthPercent);
// Log的颜色设置:
// 第二个参数是是用来控制颜色的。
//"this is Grey Text"
UE_LOG(YourLog,Log,TEXT("This is grey text!"));
//"this is Yellow Text"
UE_LOG(YourLog,Warning,TEXT("This is yellow text!"));
//"This is Red Text"
UE_LOG(YourLog,Error,TEXT("This is red text!"));
文章参考:
Ue4的UE_LOG
https://www.cnblogs.com/blueroses/p/6037981.html
https://zhuanlan.zhihu.com/p/469324623
Logging
https://unrealcommunity.wiki/logging-lgpidy6i
官方说明(以上若不明请详看以下)
// Formatting Examples Quick Reference
// 1. Logging an FString
UE_LOG(LogTemp, Warning, TEXT("The Actor's name is %s"), *YourActor->GetName());
// 2. Logging a Bool
UE_LOG(LogTemp, Warning, TEXT("The boolean value is %s"), ( bYourBool ? TEXT("true") : TEXT("false") ));
// 3. Logging an Integer
UE_LOG(LogTemp, Warning, TEXT("The integer value is: %d"), YourInteger);
// 4. Logging a Float
UE_LOG(LogTemp, Warning, TEXT("The float value is: %f"), YourFloat);
// 5. Logging an FVector
UE_LOG(LogTemp, Warning, TEXT("The vector value is: %s"), *YourVector.ToString());
// 6. Logging with Multiple Specifiers
UE_LOG(LogTemp, Warning, TEXT("Current values are: vector %s, float %f, and integer %d"), *YourVector.ToString(), YourFloat, YourInteger);