# C++ UE Logging made easier

**URL:** <https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, CPP\
**Created:** [February 8, 2023, 11:51pm UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870 "2023-02-08T23:51:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToronjaAtomica](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/toronjaatomica/32/88708_2.png) [@ToronjaAtomica](https://forums.unrealengine.com/u/ToronjaAtomica)\
**Post date:** [February 8, 2023, 11:51pm UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/1 "2023-02-08T23:51:55Z")

</div>

Hello all, I’m getting into C++ and I realized I was adding many logs. The line to print a log is quite long, so I came up with a shorter version.

Original:

```auto
UE_LOG(LogDedicatedServer, Warning, TEXT("This is a log"));

```

My idea was to move this to a common place to be used throughout the whole project.  
First we need to add a new macro, you can do it in any header file:

```auto
#define LOG(Message) UE_LOG(LogTemp, Warning, TEXT("[%s:%d] - %s"), *FString( __FUNCTION__ ), *FString::FromInt( __LINE__ ), *Message)

```

* * *

This will allow to log by using the following line:

```auto
LOG("This is a log test");

```

* * *

Now the question is, how to add parameters to it? What if I want to log a constant text with a variable?  
The next macro comes in hand:

```auto
#define LOG_P1(Message, Param1) LOG(FString::Printf(TEXT(Message), *Param1))

```

Now, to use this:

```auto
LOG_P1("[%s] Trying to load items but not on server", CharacterName);

```

* * *

How the file looks with a method for two parameters:

```auto
#define LOG(Message) UE_LOG(LogDedicatedServer, Warning, TEXT("[%s:%d] - %s"), *FString( __FUNCTION__ ), *FString::FromInt( __LINE__ ), *Message)
#define LOG_P1(Message, Param1) LOG(FString::Printf(TEXT(Message), *Param1))
#define LOG_P2(Message, Param1, Param2) LOG(FString::Printf(TEXT(Message), *Param1, *Param2))

```

How to use it:

```auto
LOG("There was an error when updating database!");
LOG_P1("[%s] Trying to load items but not on server", CharacterName);
LOG_P2("About to update item [%s] location for [%s] ...", ItemUniqueId, CharacterName);

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [February 9, 2023, 1:08am UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/2 "2023-02-09T01:08:03Z")

</div>

you could do

```auto
#define LOG(Message, ...) UE_LOG(LogCategory, LogLevel, TEXT(Message), __VA_ARGS__ )

```

then you only need the one for as many args as you need.

---

<div class="post-metadata">

**Author:** ![ToronjaAtomica](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/toronjaatomica/32/88708_2.png) [@ToronjaAtomica](https://forums.unrealengine.com/u/ToronjaAtomica)\
**Post date:** [February 9, 2023, 4:29pm UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/3 "2023-02-09T16:29:30Z")

</div>

Indeed, I thought about that later.

---

<div class="post-metadata">

**Author:** ![scurvydoggy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@scurvydoggy](https://forums.unrealengine.com/u/scurvydoggy)\
**Post date:** [December 10, 2023, 12:31pm UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/4 "2023-12-10T12:31:09Z")

</div>

This is great, thank you!

---

<div class="post-metadata">

**Author:** ![FergiusTerro](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fergiusterro/32/1020723_2.png) [@FergiusTerro](https://forums.unrealengine.com/u/FergiusTerro)\
**Post date:** [October 26, 2024, 2:58pm UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/5 "2024-10-26T14:58:01Z")

</div>

We’ve released [Game Logs System (GLS)](https://forums.unrealengine.com/t/game-logs-system-gls-efficient-log-management-in-real-time/2083983), a plugin that allows you to view logs directly in your game through a dedicated overlay. With GLS, you can instantly access detailed logs and apply flexible filters by class, object, tag, and more, even in shipping builds. It’s compatible across platforms and supports gamepad and touchscreen input for easy use on consoles and mobile devices.

If you’re looking for a way to streamline debugging, GLS is available on the [Unreal Fab](https://www.fab.com/listings/c558f5b4-0b5f-4342-acb4-c17461e541e8)!

---

<div class="post-metadata">

**Author:** ![eblade](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eblade](https://forums.unrealengine.com/u/eblade)\
**Post date:** [January 29, 2025, 1:40am UTC](https://forums.unrealengine.com/t/c-ue-logging-made-easier/766870/6 "2025-01-29T01:40:42Z")

</div>

For what it’s worth, UE\_LOGFMT is probably now the preferred logging method.
