# How to pass variable LogCategory to UE\_LOG?

**URL:** <https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [April 20, 2018, 2:21am UTC](https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108 "2018-04-20T02:21:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![staticvoidlol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@staticvoidlol](https://forums.unrealengine.com/u/staticvoidlol)\
**Post date:** [April 20, 2018, 2:21am UTC](https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108/1 "2018-04-20T02:21:54Z")

</div>

Hi There,

I’m trying to write some helper functions which require passing around FLogCategory variables which in turn should be used somehow in the call to UE\_LOG. I’m banging my head against this and can’t figure it out. Any ideas on how to achieve this?

```
void UPWNLogger::LogCat(const FLogCategoryBase& Kategory)
{
	// Get log category name
	FName logCatName = Kategory.GetCategoryName();

	UE_LOG(LogTemp, Warning, TEXT("%s"), *(n.ToString()));	// Prints the expected log category as a string value using LogTemp category
	UE_LOG(logCatName.ToString(), Warning, TEXT("%s"), *(n.ToString()));	// Results in error 'FLogCategorylogCatName': undeclared identifier
}
```

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 20, 2018, 7:22am UTC](https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108/2 "2018-04-20T07:22:13Z")

</div>

You need to declare log category first, you can read about it here:

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

If you want to do easy quick debug you can also use GLog-\>Log(FString) which is easiest way to log but bypass advance log features.

---

<div class="post-metadata">

**Author:** ![staticvoidlol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@staticvoidlol](https://forums.unrealengine.com/u/staticvoidlol)\
**Post date:** [April 20, 2018, 5:11pm UTC](https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108/3 "2018-04-20T17:11:43Z")

</div>

Thanks . The issue is not how to declare a custom log category, I have already done that and it’s working fine. My issue is that I want to write some helper methods (not macros) that in turn calls the UE\_LOG macro with specifically prepared data. In order to do this I need to pass my log category to a function (as in my first post) which seems to be working, however the issue is I can’t figure out how to use that variable when calling UE\_LOG.

Essentially it seems that when passing my variable “logCatName” to UE\_LOG it is not evaluated, and instead the macro takes the variable name (“logCatName”) and prepends “FLogCategory” to result in the string “FLogCategorylogCatName” which cannot be resolved (as it doesn’t exist).

I have very little experience with C++ macros so I’m probably trying something stupid here, but any suggestions will be appreciated.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [April 20, 2018, 9:23pm UTC](https://forums.unrealengine.com/t/how-to-pass-variable-logcategory-to-ue-log/423108/4 "2018-04-20T21:23:03Z")

</div>

Ah ok :\> Then it can’t be helped as those macros are made that way, you might try to look up on how UE\_LOG is made and try to reproduce it, code from macro is pasted at point there are used so if you can declare your own fixed macro it should work the same way

[https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Core/Public/Logging/LogMacros.h](https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Core/Public/Logging/LogMacros.h)

just remember to make NO\_LOGGING conditioning same as code above do, if you don’t do that log will embeded in to binary even if logging system is no build which might lead in to some complications. UE4 use macros for that execly because of that to control whatever log messages and or not will be build in to binary.

You might try to experiment with GLog more, there bits of category system there too:

> **[FOutputDevice](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Core/Misc/FOutputDevice/)**
>
> An output device.
