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:自定义log

转载自:http://www.cnblogs.com/pengyingh/articles/5472998.html

头文件中加入:

#pragma once

#include "GameFramework/Actor.h"
#include "FloatingActor.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(YourLog, Log, All);

cpp文件中加入:

#include "FirstProject.h"
#include "FloatingActor.h"

DEFINE_LOG_CATEGORY(YourLog);

使用

UE_LOG(YourLog, Warning, TEXT("Test UE_LOG %d"), rand());
方式4:自定义log方式2
DEFINE_LOG_CATEGORY_STATIC(LogGameNetworkManager, Log, All);

其中:LogGameNetworkManager为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

%userprofile%\AppData\Local\[Project]\Saved\Logs

Linux

UE4 shipping log directory:
/root/.config/Epic/Stars/Saved/Logs

UE4 shipping config directory:
/root/.config/Epic/Stars/Saved/Config

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]
LogWindows: Error: [Callstack] 0x00007ffba91bbac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
LogWindows: Error: [Callstack] 0x00007ffba93b00e2 UE4Editor-CoreUObject.dll!UObject::CallFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:904]
LogWindows: Error: [Callstack] 0x00007ffba93ccbc1 UE4Editor-CoreUObject.dll!UObject::ProcessContextOpcode() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:2314]
LogWindows: Error: [Callstack] 0x00007ffba93ce98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
LogWindows: Error: [Callstack] 0x00007ffba93a5efb UE4Editor-CoreUObject.dll!ProcessScriptFunction<void (__cdecl*)(UObject *,FFrame &,void *)>() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:809]
LogWindows: Error: [Callstack] 0x00007ffba93ce6a9 UE4Editor-CoreUObject.dll!ProcessLocalFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1033]
LogWindows: Error: [Callstack] 0x00007ffba93ce98d UE4Editor-CoreUObject.dll!ProcessLocalScriptFunction() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:974]
LogWindows: Error: [Callstack] 0x00007ffba93ce378 UE4Editor-CoreUObject.dll!UObject::ProcessInternal() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1058]
LogWindows: Error: [Callstack] 0x00007ffba91bbac8 UE4Editor-CoreUObject.dll!UFunction::Invoke() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\class.cpp:4643]
LogWindows: Error: [Callstack] 0x00007ffba93cdf07 UE4Editor-CoreUObject.dll!UObject::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\coreuobject\private\uobject\scriptcore.cpp:1464]
LogWindows: Error: [Callstack] 0x00007ffba5bb9ff3 UE4Editor-Engine.dll!AActor::ProcessEvent() [d:\build\++ue4\sync\engine\source\runtime\engine\private\actor.cpp:769]
LogWindows: Error: [Callstack] 0x00007ffba6cb5bf9 UE4Editor-Engine.dll!AActor::ReceiveActorBeginOverlap() [d:\build\++ue4\sync\engine\intermediate\build\win64\ue4editor\inc\engine\actor.gen.cpp:909]
LogWindows: Error: [Callstack] 0x00007ffba5f6dd49 UE4Editor-Engine.dll!UPrimitiveComponent::BeginComponentOverlap() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:2510]
LogWindows: Error: [Callstack] 0x00007ffba5fa97ef UE4Editor-Engine.dll!UPrimitiveComponent::UpdateOverlapsImpl() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\primitivecomponent.cpp:2926]
LogWindows: Error: [Callstack] 0x00007ffba5fd41a1 UE4Editor-Engine.dll!USceneComponent::EndScopedMovementUpdate() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:840]
LogWindows: Error: [Callstack] 0x00007ffba5fbba43 UE4Editor-Engine.dll!FScopedMovementUpdate::~FScopedMovementUpdate() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:3421]
LogWindows: Error: [Callstack] 0x00007ffba5f30e0a UE4Editor-Engine.dll!UCharacterMovementComponent::PerformMovement() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\charactermovementcomponent.cpp:2364]
LogWindows: Error: [Callstack] 0x00007ffba5f54441 UE4Editor-Engine.dll!UCharacterMovementComponent::TickComponent() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\charactermovementcomponent.cpp:1257]
LogWindows: Error: [Callstack] 0x00007ffba5eef3fa UE4Editor-Engine.dll!FActorComponentTickFunction::ExecuteTickHelper<<lambda_04d8ef4b869923d6312932fb3543d049> >() [d:\build\++ue4\sync\engine\source\runtime\engine\classes\gameframework\actor.h:3109]
LogWindows: Error: [Callstack] 0x00007ffba5f15464 UE4Editor-Engine.dll!FActorComponentTickFunction::ExecuteTick() [d:\build\++ue4\sync\engine\source\runtime\engine\private\components\actorcomponent.cpp:816]
LogWindows: Error: [Callstack] 0x00007ffba6b572bc UE4Editor-Engine.dll!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4\sync\engine\source\runtime\core\public\async    askgraphinterfaces.h:842]
LogWindows: Error: [Callstack] 0x00007ffba83e22d8 UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4\sync\engine\source\runtime\core\private\async    askgraph.cpp:686]
LogWindows: Error: [Callstack] 0x00007ffba83e2563 UE4Editor-Core.dll!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4\sync\engine\source\runtime\core\private\async    askgraph.cpp:582]
LogWindows: Error: [Callstack] 0x00007ffba83f2309 UE4Editor-Core.dll!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4\sync\engine\source\runtime\core\private\async    askgraph.cpp:1457]
LogWindows: Error: [Callstack] 0x00007ffba6b9f9e3 UE4Editor-Engine.dll!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private    icktaskmanager.cpp:557]
LogWindows: Error: [Callstack] 0x00007ffba6babd12 UE4Editor-Engine.dll!FTickTaskManager::RunTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private    icktaskmanager.cpp:1505]
LogWindows: Error: [Callstack] 0x00007ffba63cdc4f UE4Editor-Engine.dll!UWorld::RunTickGroup() [d:\build\++ue4\sync\engine\source\runtime\engine\private\leveltick.cpp:789]
LogWindows: Error: [Callstack] 0x00007ffba63d7e28 UE4Editor-Engine.dll!UWorld::Tick() [d:\build\++ue4\sync\engine\source\runtime\engine\private\leveltick.cpp:1568]
LogWindows: Error: [Callstack] 0x00007ffba3ee02f7 UE4Editor-UnrealEd.dll!UEditorEngine::Tick() [d:\build\++ue4\sync\engine\source\editor\unrealed\private\editorengine.cpp:1618]
LogWindows: Error: [Callstack] 0x00007ffba46fd396 UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick() [d:\build\++ue4\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:403]
LogWindows: Error: [Callstack] 0x00007ff6ba396bb1 UE4Editor.exe!FEngineLoop::Tick() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launchengineloop.cpp:3967]
LogWindows: Error: [Callstack] 0x00007ff6ba3a554c UE4Editor.exe!GuardedMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\launch.cpp:168]
LogWindows: Error: [Callstack] 0x00007ff6ba3a55ca UE4Editor.exe!GuardedMainWrapper() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:145]
LogWindows: Error: [Callstack] 0x00007ff6ba3b316c UE4Editor.exe!WinMain() [d:\build\++ue4\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:275]
LogWindows: Error: [Callstack] 0x00007ff6ba3b5b8e UE4Editor.exe!__scrt_common_main_seh() [d:\agent\_work\3\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
LogWindows: Error: [Callstack] 0x00007ffc093a7bd4 KERNEL32.DLL!UnknownFunction ]
LogWindows: Error: [Callstack] 0x00007ffc0a1ece71 ntdll.dll!UnknownFunction ]
LogWindows: Error:
LogExit: Executing StaticShutdownAfterError
LogWindows: FPlatformMisc::RequestExit(1)
Log file closed, 07/19/19 02:43:33

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
    };
}

References

Blogs

UE4日志级别设置
https://www.jianshu.com/p/c550c3223a95

[UE4] About UE_LOG
https://historia.co.jp/archives/5532/