UE4:Log显示级别

UE4:Log显示级别

Log Verbosity Levels

Log的输出级别有四个地方控制

  1. CompileTime verbosity
  2. Default verbosity
  3. ini verbosity
  4. Runtime verbosity

CompileTime Verbosity和Default Verbosity指的就是

1
DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)

的参数
在源码里定义如下

1
2
3
4
5
6
7
8
9
10
11
/** 
* A macro to declare a logging category as a C++ "extern", usually declared in the header and paired with DEFINE_LOG_CATEGORY in the source. Accessible by all files that include the header.
* @param CategoryName, category to declare
* @param DefaultVerbosity, default run time verbosity
* @param CompileTimeVerbosity, maximum verbosity to compile into the code
**/
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity) \
extern struct FLogCategory##CategoryName : public FLogCategory<ELogVerbosity::DefaultVerbosity, ELogVerbosity::CompileTimeVerbosity> \
{ \
FORCEINLINE FLogCategory##CategoryName() : FLogCategory(TEXT(#CategoryName)) {} \
} CategoryName;

编译时如果Default Verbosity甚至大于CompileTime Verbosity,这个log就不会被编译进代码,运行时就不存在这个log
Default Verbosity就是运行时默认的log级别
Ini verbosity是在DefaultEngine.ini添加配置来控制对应的log级别。在DefaultEngine.ini中添加section :[Core.log],可以控制log的显示级别.
eg:
log使用的时候是
UE_LOG(CategoryName, Verbosity, Format, …)
在配置文件中加上log的section
[Core.Log]
global=Log
LogAnimMontage = VeryVerbose

在ini中配置的级别会覆盖DefaultVerbosity
用控制台启动游戏时可以通过参数来调整log级别
比如: -LogCmds=“foo verbose, bar off”
在游戏运行时还可以通过控制台命令修改显示级别
比如:Log [cat] [level]
会覆盖ini中的配置

LogAnimMontage 是CategoryName,那么这个Category的log的输出级别控制就会被改为VeryVerbose
global则是其他没有单独指定的Category的输出级别
log的显示级别定义在LogVerbosity.h中,log输出的时候,只会输出小于等于设置的最高级别的log

eg:
我在一个函数里写了一堆log:

1
2
3
4
5
6
7
8
9
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogMylog, VeryVerbose, TEXT("Display Log."));
UE_LOG(LogMylog, Verbose, TEXT("Display Log."));
UE_LOG(LogMylog, Display, TEXT("Display Log."));
UE_LOG(LogMylog, Warning, TEXT("Display Log."));
UE_LOG(LogMylog, Error, TEXT("Display Log."));
}

默认情况下打印出来的是这样:
20220222225351

然后修改ini配置
[Core.Log]
global= Error
LogMylog = VeryVerbose

启动后的log:
20220222231254

官方文档ELogVerbosity

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
};
}

UE4:Log显示级别
http://muchenhen.com/posts/12189/
作者
木尘痕
发布于
2022年2月18日
许可协议