How do I log a simple string?

I am not sure how to log a simple string. I found the UE_LOG macro but it is not obvious to me how to use it.

1 Like

To make your own log category you can do the following:

In a header:
DECLARE_LOG_CATEGORY_EXTERN(MyLogCategory, Log, All);

In a cpp:
DEFINE_LOG_CATEGORY(MyLogCategory)

Note: There are other ways to setup log categories (see AssertionMacros.h)

to use:

UE_LOG(MyLogCategory, Log, TEXT(“This is my message that prints to the log. It works like printf”) );

The second parameter is verbosity and there are many levels of vebosity. The can be found in the ELogVerbosity enum in OutputDevice.h. The “fatal” verbosity level will cause an assertion when used.

UE_LOG also works like printf. E.G:

UE_LOG(MyLogCategory, Log, TEXT(“I have %d cats”), 2 );

if you just want something quick and dont want to setup your own category you can use the LogTemp category:

UE_LOG(LogTemp, Log, … );

Adding to Matt’s wonderful answer,

I’ve created a Wiki page for Logs!

Thanks, that helped me a lot.

You can also use

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT(“This is the log!”));

to write some text on the screen, useful if you need to check if your function is being called or not.

If you’re lazy - and who isn’t - you can use macros to make it even easier.
See Wiki: Log Macro with Netmode and Colour.

Thanks for writing up the Wiki, Rama!