[UE4]UE_LOG & ScreenDebugMessage Notes
Keywords: UE4 UE_LOG & ScreenDebugMessage Notes
UE_LOG
方式1:GLog
GLog->Log("Does something");
方式2:UE_LOG(LogTemp)
UE_LOG(LogTemp, Log, TEXT("%d"), 1111);
UE_LOG(LogTemp, Warning, TEXT("%d"), 1111);
方式3:一处定义,多处使用
单个头文件中声明:MyTest.h
#pragma once
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(MyTestLog, Log, All);
对应的CPP中定义:MyTest.cpp
#include "MyTest.h"
DEFINE_LOG_CATEGORY(MyTestLog);
其他cpp文件中使用:
#include "MyTest.h"
MyBlueprintLibrary::DoWork()
{
UE_LOG(MyTestLog, Display, TEXT("Work start!"));
}
使用DECLARE_LOG_CATEGORY_EXTERN声明时,一定要加上前缀,比如 MYGAME_API。
方式4:仅在指定的单个CPP中使用
单个CPP中定义后,只在当前CPP范围内使用:
DEFINE_LOG_CATEGORY_STATIC(LogNetwork, Log, All);
其中:LogNetwork为Log名,Log为运行时log级别,All为编译期间的log级别。
方式1和方式2的输出结果
Does something
LogTemp: 1111
LogTemp: Warning: 1111(黄色)
修改log输出文件的文件名
启动命令行追加:
LOG=my_custom_log_file.log
或者:
ABSLOG=E:/my_custom_log_file.log
Low Level Log
LowLevelOutputDebugString
FPlatformMisc::LowLevelOutputDebugString(TEXT("Waited for 10 seconds on IO...."));
AddOnScreenDebugMessage
How to display screen debug message in fixed row
//display messag in second row (key = 1) when there're mulitple message in screen.
GEngine->AddOnScreenDebugMessage(1, 1.f, FColor::Green, FString("aaaaa"), false);
bNewerOnTop
only works with Key == INDEX_NONE
Building Log
Build log from engine source building
D:\UnrealEngine-4.10.0-release\Engine\Programs\AutomationTool\Saved\Logs\
Build log from installed distributions of engine
TODO
Game log directory on shipping
Windows
Game: %localappdata%\<ProjectName>\Saved\Logs
Server: WindowsServer\<ProjectName>\Saved\Logs
(e.g Windows)
Linux
UE4 shipping log directory:
/root/.config/Epic/[YourGame]/Saved/Logs
UE4 shipping config directory:
/root/.config/Epic/[YourGame]/Saved/Config
Error Message Box
FTextBuilder ErrorMessage;
ErrorMessage.AppendLine(FText::FromString(TEXT("GPU Driver Issue.\n")));
ErrorMessage.AppendLine(FText::FromString(TEXT("Please update the latest driver.\r")));
FPlatformMisc::MessageBoxExt(EAppMsgType::Ok, *ErrorMessage.ToText().ToString(), TEXT("Error"));
FPlatformMisc::RequestExit(true, TEXT("GPU Device Issue"));
Issues
Crash in LogMacros.cpp
LogAresMessageBus: ON ACTOR SPAWNED!
LogWindows: Error: === Critical error: ===
LogWindows: Error:
LogWindows: Error: Fatal error!
LogWindows: Error:
LogWindows: Error: Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000001
LogWindows: Error:
LogWindows: Error: [Callstack] 0x00007ffc07e92ebd ucrtbase.dll!UnknownFunction ]
LogWindows: Error: [Callstack] 0x00007ffc07e7f10c ucrtbase.dll!UnknownFunction ]
LogWindows: Error: [Callstack] 0x00007ffc07e7eac7 ucrtbase.dll!UnknownFunction ]
LogWindows: Error: [Callstack] 0x00007ffba85398a7 UE4Editor-Core.dll!FMsg::Logf_InternalImpl() [d:\build\++ue4\sync\engine\source\runtime\core\private\logging\logmacros.cpp:99]
LogWindows: Error: [Callstack] 0x00007ffb918d55bf UE4Editor-Ares.dll!UAresMessageBus::Publish() [A:\Projekte\Unreal-Engine-4-Projekte\Ares\Source\Ares\Core\AresMessageBus.cpp:61]
LogWindows: Error: [Callstack] 0x00007ffb918d6b84 UE4Editor-Ares.dll!UAresMessageBus::execPublish() [A:\Projekte\Unreal-Engine-4-Projekte\Ares\Source\Ares\Core\AresMessageBus.h:26]
Solution:
Don’t use UE_LOG
in non-GameThread of Unreal.
Crash when printing inside function
https://forums.unrealengine.com/t/crash-when-printing-inside-function/128904
Verbosity Levels
Verbosity Levels in source
Engine\Source\Runtime\Core\Public\Logging\LogVerbosity.h
/**
* Enum that defines the verbosity levels of the logging system.
* Also defines some non-verbosity levels that are hacks that allow
* breaking on a given log line or setting the color.
**/
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
};
}
Where to change verbosity level of engine
Engine\Source\Runtime\Engine\Public\EngineLogs.h
References
Blogs
UE4日志级别设置
https://www.jianshu.com/p/c550c3223a95
[UE4] About UE_LOG
https://historia.co.jp/archives/5532/