UE_LOG in Unreal Engine

Published on

How to print any info to the Output Log in the Unreal Engine?

Platforma

UE_LOG

UE_LOG is a macro that logs a formatted message into the log file.

UE_LOG(<a href="#log_category">&lt;LOG_CATEGORY&gt;</a>, <a href="#ELogVerbosity" target="_blank">&lt;VERBOSITY_LEVEL&gt;</a>, <a href="#info">&lt;TEXT_INFORMATION&gt;</a>);
Sample:
UE_LOG(LogTemp, Display, TEXT("Hello World"));

UE_LOG Properties

  • LOG_CATEGORY

    LogTemp

    Declare custom category

  • ELogVerbosity

    ValueDescriptionPrinted in ConsolePrinted in Editor LogText Color
    NoLoggingNot used
    FatalAlways prints a fatal error to console (and log file) and crashes (even if logging is disabled)YesNANA
    ErrorPrints an error to console (and log file).YesYesRed
    WarningPrints a warning to console (and log file).YesYesYellow
    DisplayPrints a message to console (and log file)YesYesGrey
    LogPrints a message to a log file (does not print to console)NoYesGrey
    VerbosePrints a verbose message to a log file (if Verbose logging is enabled for the given category, usually used for detailed logging)NoNoNA
    VeryVerbosePrints a verbose message to a log file (if VeryVerbose logging is enabled, usually used for detailed logging that would otherwise spam output)NoNoNA
    All = VeryVerbose
    NumVerbosity
    VerbosityMask = 0xf
    SetColor = 0x40
    BreakOnLog = 0x80
  • TEXT_INFORMATION

    Data TypeExample
    FString
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"An Actor's name is %s"</span>), *ExampleActor-&gt;<span class="cc_yellow">GetName</span>());
    Bool
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"The boolean value is %s"</span>), ( bExampleBool ? <span class="cc_yellow">TEXT</span>(<span class="cc_green">"true"</span>): <span class="cc_yellow">TEXT</span>(<span class="cc_green">"false"</span>) ));
    Integer
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"The integer value is: %d"</span>), ExampleInteger);
    Float
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"The float value is: %f"</span>), ExampleFloat);
    FVector
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"The vector value is: %s"</span>), *ExampleVector.<span class="cc_yellow">ToString</span>());
    Multiple Specifiers
    <span UE_LOG(LogTemp, Warning, <span class="cc_yellow">TEXT</span>(<span class="cc_green">"Current values are: vector %s, float %f, and integer %d"</span>), *ExampleVector.<span class="cc_yellow">ToString</span>(), ExampleFloat, ExampleInteger);

UE_LOGFMT

UE_LOGFMT records a structured log event that supports Positional or Named parameters but can not mix both styles. To use this macro you, need to include the Logging/StructuredLog.h library declaration.

UE_LOGFMT was introduced with Unreal Engine 5.2.

Parameter NameDescription
Positional

When using positional parameters, the field values must exactly match the field referenced by format.

For example:

<span class="cc_yellow">UE_LOGFMT</span>(LogCore, Warning, <span class="cc_green">"Loading `{Name}` failed with error {Error}"</span>, Package-&gt;<span class="cc_yellow">GetName</span>(),  ErrorCode);
                                    
Named

When using Named parameters, the field values must contain every field reference by format. The order is irrelevant and extra fields are permitted.

For example:

<span class="cc_yellow">UE_LOGFMT</span>(LogCore, Warning, <span class="cc_green">"Loading `{Name}` failed with error {Error}"</span>,(<span class="cc_green">"Name"</span>, Package-&gt;<span class="cc_yellow">GetName</span>()), (<span class="cc_green">"Error"</span>, ErrorCode),(<span class="cc_green">"Flags"</span>, LoadFlags));
                                        

Field names must match the "[A-Za-z0-9_]+" format and must be unique within this log event. Field values are serialized using SerializeForLog or the operator <<(FCbWriter&, FieldType).

  • CategoryName: Name of a log category declared by DECLARE_LOG_CATEGORY_*.

  • Verbosity: Name of a log verbosity level from ELogVerbosity.

  • Format: Formats the string in the style of FLogTemplate.

  • Fields[0-16]: Zero to sixteen fields or field values.

Vrealmatic consulting

Anything unclear?

Let us know!

Contact Us