以下两个步骤均完成才可

1、声明自定义日志分类

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;

参数说明:

CategoryName 自定义日志分类名称

Log开头 DefaultVerbosity 日志默认级别,一般使用Log

CompileTimeVerbosity 日志编译级别 高于此级别的不会被编译 一般用All

这个操作需要在头文件中完成,并且完成一次

2、定义日志分类

定义

1
2
3
4
5
/** 
* A macro to define a logging category, usually paired with DECLARE_LOG_CATEGORY_EXTERN from the header.
* @param CategoryName, category to define
**/
#define DEFINE_LOG_CATEGORY(CategoryName) FLogCategory##CategoryName CategoryName;

参数说明:

CategoryName 自定义日志分类名称

这个操作必须在CPP文件中进行,只需要进行一次定义