Opens an external site in a new window
Mental Health Awareness Month
“Community”
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links
  • Profile
RODNEY LAB
  • Home
  • Plus +
  • Newsletter
  • Links

UE5 C++ Logging: Unreal Engine Custom Logger & UE_LOGFMT 📝 # UE5 C++ Logging: Unreal Engine Custom Logger & UE_LOGFMT 📝 #

blurry low resolution placeholder image UE5 C++ Logging
  1. Home Rodney Lab Home
  2. Blog Posts Rodney Lab Blog Posts
  3. C++ C++ Blog Posts
<PREVIOUS POST
NEXT POST >
LATEST POST >>

UE5 C++ Logging: Unreal Engine Custom Logger & UE_LOGFMT 📝 #

Published: 2 years ago
4 minute read
Gunning Fog Index: 5
Content by Rodney
blurry low resolution placeholder image Author Image: Rodney from Rodney Lab
SHARE:

📝 Logging in UE5 #

In this UE5 C++ logging post, we see a few ways for logging in Unreal Engine 5, including UE_LOGFMT. UE_LOGFMT provides modern string interpolation, offered in std::format, std::print and libraries like fmtlib and spdlog.

As well as that, we see a way for customizing your Unreal log messages, included in your own C++ source files. This can help to filter log messages generated by your code from the engine’s own code, speeding up your debugging process.

If that’s what you were looking for, let’s crack on. Please get in touch with any feedback on the post, especially if it is possible to make any aspect clearer.

🖥️ Main Logging Methods in UE5 C++ Code #

Before Unreal Engine 5.2, you were limited to:

  • GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("Hello Everybody!"));; and
  • UE_LOG(LogTemp, Warning, TEXT("Hello Everybody!"));.

The TEXT macro, above, provides C printf style formatting . Modern C++ style guides prefer C++ approaches over printf  though; printf can introduce safety issues  and does not support user-defined types. A good solution (working in older versions of Unreal Engine) is to use std::format (added in C++20) or alternatively, std::print (added in C++23) or a third-party modern formatting library like fmtlib .

If you are using Unreal Engine 5.2 or newer, you can use UE_LOGFMT, with string interpolation, which we see next.

🛸 Modern UE5 Logging with UE_LOGFMT #

Unreal Engine 5.2 and newer offer UE_LOGFMT is available , which has an arguably cleaner API for logging and provides with string interpolation.

Here is a before and after comparison, to see how you can update code to use the new API:

Before (UE_LOG)

    
UE_LOG(LogTemp, Warning, TEXT("Hello Everybody!"));

After (UE_LOGFMT)

    
UE_LOGFMT(LogCore, Warning, "Loading `{Name}` failed with error {Error}", Package->GetName(), ErrorCode);

This will look familiar if you have used any of the string formatting alternatives mentioned above. To sue this new logging macro, just add the following header to source files you use UE_LOGFMT in.

    
#include "Logging/StructuredLog.h"

As an alternative, add this header to the project CPP file, like we do below with custom logging.

🪚 Custom UE5 C++ Logging #

Moving on, custom logging, is relatively easy to set up. The advantage of using it, is that you can quickly filter Unreal Engine log messages from your own modules.

To start, create a new CustomLogging.h header file in your project code under YourProject/Source/YourProject/Private/. Create the Private directory if the project does not already have one. Add this code to the new file:

YourProject/Source/YourProject/Private/CustomLogging.h
cpp
    
1 #pragma once
2
3 #include "CoreMinimal.h"
4 #include "Logging/StructuredLog.h"
5
6 /* Custom log category */
7 DECLARE_LOG_CATEGORY_EXTERN(YourCustomLogName, Log, All);

Replace YourCustomLogName with whatever you want to appear in the logs against the custom messages. The second and third parameters here are the default severity and which levels of severity to include.

Including Logging/StructuredLog.h (in line 4) will give you access to UE_LOGFMT when you include this header file in other source files.

Making Custom Logs Available to the Engine #

Next, open the project file (YourProject/Source/YourProject/YourProject.cpp), and include your new header and the extra line at the bottom here:

YourProject/Source/YourProject/YourProject.cpp
cpp
    
1 // Copyright Epic Games, Inc. All Rights Reserved.
2
3 #include "YourProject.h"
4 #include "CustomLogging.h"
5 #include "Modules/ModuleManager.h"
6
7 IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, YourProject, "YourProject" );
8
9 DEFINE_LOG_CATEGORY(YourCustomLogName);

You might need to refresh the project in the Unreal Engine Editor, for it to pick up the new header. You can now use custom logs, with UE_LOG or UE_LOGFMT in your C++ source files.

YourProject/Source/SomeSourceFile.cpp
cpp
    
1 // ...TRUNCATED
2
3 #include "CustomLogging.h"
4
5 // TRUNCATED...
6
7 Foo::Foo() {
8 UE_LOGFMT(YourCustomLogName, Warning, "Made it here!");
9 }

🗳 Poll #

How do you format output in C++, outside of Unreal Engine?
Voting reveals latest results.

🙌🏽 UE5 C++ Logging: Wrapping Up #

In this UE5 C++ logging post, we had a look at the options for logging from your C++ code. More specifically, we saw:

  • the new UE_LOGFMT macro in action;
  • alternatives to UE_LOG string interpolation for working with older versions of Unreal Engine; and
  • how you can create custom logs in Unreal Engine, making filtering your own code’s message simpler.

I hope you found this useful. Do let me know if you would like to see more similar content. Also reach out if there is anything I could improve to provide a better experience for you.

🙏🏽 UE5 C++ Logging: Feedback #

If you have found this post useful, see links below for further related content on this site. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.

blurry low resolution placeholder image ask Rodney X (formerly Twitter) avatar

Rodney

@askRodney

Just dropped a new post on setting up custom logging in Unreal Engine, for faster debugging.

Also look at adding string interpolation to UE5 C++ log message using the new UE_LOGFMT macro.

Hope you find it useful!

https://t.co/Xn6wphFWux #askRodney

— Rodney (@askRodney) March 6, 2024

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on X (previously Twitter) and also, join the #rodney  Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Game Dev as well as Rust and C++ (among other topics). Also, subscribe to the newsletter to keep up-to-date with our latest projects.

Thanks for reading this post. I hope you found it valuable. Please get in touch with your feedback and suggestions for posts you would like to see. Read more about me …

blurry low resolution placeholder image Rodney from Rodney Lab
TAGS:
C++GAMING

Related Posts

blurry low resolution placeholder image Creating C++ Sphinx Docs: using Doxygen and Breathe 📚

Creating C++ Sphinx Docs: using Doxygen and Breathe 📚

c++
gaming
<PREVIOUS POST
NEXT POST >
LATEST POST >>

Leave a comment …

Your information will be handled in line with our Privacy Policy .

Ask for more

1 Nov 2022 — Astro Server-Side Rendering: Edge Search Site
3 Oct 2022 — Svelte eCommerce Site: SvelteKit Snipcart Storefront
1 Sept 2022 — Get Started with SvelteKit Headless WordPress

Copyright © 2020 – 2025 Rodney Johnson. All Rights Reserved. Please read important copyright and intellectual property information.

  • Home
  • Profile
  • Plus +
  • Newsletter
  • Contact
  • Links
  • Terms of Use
  • Privacy Policy
We use cookies  to enhance visitors’ experience. Please click the “Options” button to make your choice.  Learn more here.