注意:html
把log相關兩個宏寫到類中,並編譯後,在輸出日誌的位置的Categories關鍵字過濾的位置看不到本身的標籤是由於須要先運行一次,輸出一些這個標籤的log後,這個自定義的標籤纔會顯示在這網絡
原文 https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime#Log_an_FString
app
http://www.cnblogs.com/blueroses/p/6037981.html
編輯器
說明:本文爲Wiki上的RAMA大神文章的大體翻譯函數
在遊戲模式下,你須要在遊戲的快捷方式後面加 -Log,纔會在遊戲中顯示。this
你能夠在Output窗口中看到log信息。spa
若是想在遊戲中看到,須要到Engin.ini中修改參數添加"GameCommandLine=-log,若是沒有,則須要按~,輸入-Log命令開啓。命令行
快速使用:翻譯
UE_LOG(LogTemp, Warning, TEXT("Your message"));
不用設置標籤,簡單快速。debug
在你的遊戲頭文件中加入:
//General Log DECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All); //Logging during game startup DECLARE_LOG_CATEGORY_EXTERN(YourInit, Log, All); //Logging for your AI system DECLARE_LOG_CATEGORY_EXTERN(YourAI, Log, All); //Logging for Critical Errors that must always be addressed DECLARE_LOG_CATEGORY_EXTERN(YourCriticalErrors, Log, All);
這樣輸出的Log你就能夠知道是哪一個部分的,這也是UE_Log頗有用的緣由。
在你的遊戲Cpp文件中:
//General Log DEFINE_LOG_CATEGORY(YourLog); //Logging during game startup DEFINE_LOG_CATEGORY(YourInit); //Logging for your AI system DEFINE_LOG_CATEGORY(YourAI); //Logging for Critical Errors that must always be addressed DEFINE_LOG_CATEGORY(YourCriticalErrors);
//"This is a message to yourself during runtime!" UE_LOG(YourLog,Warning,TEXT("This is a message to yourself during runtime!"));
%s strings are wanted as TCHAR* by Log, so use *FString() //"MyCharacter's Name is %s" UE_LOG(YourLog,Warning,TEXT("MyCharacter's Name is %s"), *MyCharacter->GetName() );
//"MyCharacter's Health is %d" UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %d"), MyCharacter->Health );
//"MyCharacter's Health is %f" UE_LOG(YourLog,Warning,TEXT("MyCharacter's Health is %f"), MyCharacter->Health );
//"MyCharacter's Location is %s" UE_LOG(YourLog,Warning,TEXT("MyCharacter's Location is %s"), *MyCharacter->GetActorLocation().ToString());
//"MyCharacter's FName is %s" UE_LOG(YourLog,Warning,TEXT("MyCharacter's FName is %s"), *MyCharacter->GetFName().ToString());
//"%s has health %d, which is %f percent of total health" UE_LOG(YourLog,Warning,TEXT("%s has health %d, which is %f percent of total health"), *MyCharacter->GetName(), MyCharacter->Health, MyCharacter->HealthPercent);
//"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!"));
能夠看得出第二個參數是是用來控制顏色的。
傳遞客戶端信息(網絡模式):
PlayerController->ClientMessage("Your Message");
[cat] = a category for the command to operate on, or 'global' for all categories. 標籤,沒有設置就顯示全部的Log [level] = verbosity level, one of: none, error, warning, display, log, verbose, all, default 關卡,顯示某某關卡的Log
At boot time, compiled in default is overridden by ini files setting, which is overridden by command line
Log list - list all log categories Log list [string] - list all log categories containing a substring Log reset - reset all log categories to their boot-time default Log [cat] - toggle the display of the category [cat] Log [cat] off - disable display of the category [cat] Log [cat] on - resume display of the category [cat] Log [cat] [level] - set the verbosity level of the category [cat] Log [cat] break - toggle the debug break on display of the category [cat]
-LogCmds=\"[arguments],[arguments]...\" - applies a list of console commands at boot time -LogCmds=\"foo verbose, bar off\" - turns on the foo category and turns off the bar category
Any command line option can be set via the environment variable UE-CmdLineArgs
set UE-CmdLineArgs=\"-LogCmds=foo verbose breakon, bar off\"
In DefaultEngine.ini or Engine.ini:
[Core.Log] global=[default verbosity for things not listed later] [cat]=[level] foo=verbose break
Rama後面的一篇文章提供了顯示代碼行號、函數名稱、類名等功能:https://wiki.unrealengine.com/Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!