UE_LOG in Unreal Engine

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

UE_LOG

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

UE_LOG(<LOG_CATEGORY>, <VERBOSITY_LEVEL>, <TEXT_INFORMATION>);
Sample:
UE_LOG(LogTemp, Display, TEXT("Hello World"));

UE_LOG Properties

  • LOG_CATEGORY

    LogTemp

    Declaration in header file

    DECLARE_LOG_CATEGORY_EXTERN(<LOG_CATEGORY>, <VERBOSITY_LEVEL>, All);
    sample:
    DECLARE_LOG_CATEGORY_EXTERN(MyEditorCategory, Log, All);

    Definition in cpp file

    DEFINE_LOG_CATEGORY(<LOG_CATEGORY>);
    sample:
    DEFINE_LOG_CATEGORY(MyEditorCategory);

    Logging from anywhere in the code

    UE_LOG(<LOG_CATEGORY>, <VERBOSITY_LEVEL>, Text_info);
    sample:
    UE_LOG(MyEditorCategory, Warning, TEXT("Unable to add content browser status branches, none specified"));

    Declare custom category

  • ELogVerbosity

    Value Description Printed in Console Printed in Editor Log Text Color
    NoLogging Not used
    Fatal Always prints a fatal error to console (and log file) and crashes (even if logging is disabled) Yes NA NA
    Error Prints an error to console (and log file). Yes Yes Red
    Warning Prints a warning to console (and log file). Yes Yes Yellow
    Display Prints a message to console (and log file) Yes Yes Grey
    Log Prints a message to a log file (does not print to console) No Yes Grey
    Verbose Prints a verbose message to a log file (if Verbose logging is enabled for the given category, usually used for detailed logging) No No NA
    VeryVerbose Prints a verbose message to a log file (if VeryVerbose logging is enabled, usually used for detailed logging that would otherwise spam output) No No NA
    All = VeryVerbose
    NumVerbosity
    VerbosityMask = 0xf
    SetColor = 0x40
    BreakOnLog = 0x80
  • TEXT_INFORMATION

    Data Type Example
    FString
    UE_LOG(LogTemp, Warning, TEXT("An Actor's name is %s"), *ExampleActor->GetName());
    Bool
    UE_LOG(LogTemp, Warning, TEXT("The boolean value is %s"), ( bExampleBool ? TEXT("true"): TEXT("false") ));
    Integer
    UE_LOG(LogTemp, Warning, TEXT("The integer value is: %d"), ExampleInteger);
    Float
    UE_LOG(LogTemp, Warning, TEXT("The float value is: %f"), ExampleFloat);
    FVector
    UE_LOG(LogTemp, Warning, TEXT("The vector value is: %s"), *ExampleVector.ToString());
    Multiple Specifiers
    UE_LOG(LogTemp, Warning, TEXT("Current values are: vector %s, float %f, and integer %d"), *ExampleVector.ToString(), 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 Name Description
Positional

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

For example:

UE_LOGFMT(LogCore, Warning, "Loading `{Name}` failed with error {Error}", Package->GetName(),  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:

UE_LOGFMT(LogCore, Warning, "Loading `{Name}` failed with error {Error}",("Name", Package->GetName()), ("Error", ErrorCode),("Flags", 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.