《UE4游戏开发》之 《日志系统打印类名函数和行号》

  1. 理解c/c++提供宏的的含义:__FUNCTION__表示当前类名和函数名;__LINE__调用它的代码中的当前行号
  2. 参考链接:https://www.ue4community.wiki/Logs,_Printing_Class_Name,_Function_Name,_Line_Number
  3. 关键宏拼接
//Current Class Name + Function Name where this is called!
#define CUR_CLASS_FUNC (FString(__FUNCTION__))

//Current Class where this is called!
#define CUR_CLASS (FString(__FUNCTION__).Left(FString(__FUNCTION__).Find(TEXT(":"))) )

//Current Function Name where this is called!
#define CUR_FUNC (FString(__FUNCTION__).Right(FString(__FUNCTION__).Len() - FString(__FUNCTION__).Find(TEXT("::")) - 2 ))

//Current Line Number in the code where this is called!
#define CUR_LINE  (FString::FromInt(__LINE__))

//Current Class and Line Number where this is called!
#define CUR_CLASS_LINE (CUR_CLASS + "::" + CUR_LINE)

//Current Function Signature where this is called!
#define CUR_FUNCSIG (FString(__FUNCSIG__))
//当前调用的类名::函数::行号
#define CUR_CLASS_FUNC_LINE (CUR_CLASS_FUNC + "::" + CUR_LINE)
  1. 使用实例:#define LOG(Message) UDebugLib::Log(Message + FString(" [") + CUR_CLASS_FUNC_LINE + FString("]"), EDebugLogChannel::GENERAL);
  2. 上面定义的宏,可以简单地认为可以随内容改变的字符串,所以可以应用在自己写的日志中
  3. 含有上面内容的商城免费插件:https://gitlab.com/Rorschach7/ue4debugplugin【注意直接访问需要翻墙】

猜你喜欢

转载自blog.csdn.net/qq_21919621/article/details/107811117