# How to declare Log category that can be accessed by all classes (like LogTemp)?

**URL:** <https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317>\
**Category:** C++\
**Tags:** logging, modules, unreal-engine, log, packaging-projects, CPP, question\
**Created:** [April 22, 2021, 3:02pm UTC](https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317 "2021-04-22T15:02:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![k\_a\_s\_s\_k\_a\_s\_s](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/k_a_s_s_k_a_s_s/32/555828_2.png) [@k\_a\_s\_s\_k\_a\_s\_s](https://forums.unrealengine.com/u/k_a_s_s_k_a_s_s)\
**Post date:** [April 22, 2021, 3:02pm UTC](https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317/1 "2021-04-22T15:02:45Z")

</div>

What is the process of declaring a log category that can be accessed with the UE\_LOG macro, without having to manually include some file in any class that needs to use this log category?

I have tried including it in the module .h and .cpp, but I get linking errors in some cases, like trying to include the module .h in files of another module. Sometimes things compile and run in-editor, but compiling fails for a packaged build.

Logging is an extremely basic function, and I can’t figure out how to use it without strange issues. And I haven’t found good information on it either, it’s always very basic instructions on making a log category work within one class, with no re-use instructions for a more general category.

I would very much like to be able to use a custom log category without extra include hassle, like LogTemp, which is somehow accessible in any class of any module, no linking errors.

Any help would be appreciated.

---

<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 22, 2021, 8:43pm UTC](https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317/2 "2021-04-22T20:43:50Z")

</div>

[This wiki page](https://nerivec.github.io/old-ue4-wiki/pages/logs-printing-messages-to-yourself-during-runtime.html#Setting_Up_Your_Own_Log_Category) has all the info.

---

<div class="post-metadata">

**Author:** ![MaselinoM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MaselinoM](https://forums.unrealengine.com/u/MaselinoM)\
**Post date:** [January 18, 2024, 3:06pm UTC](https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317/3 "2024-01-18T15:06:51Z")

</div>

I have also run into the same issue today and have probably found the solution to your issue. Let’s look at the example of _LogTemp_:

_CoreGlobals.h:_

```auto
CORE_API DECLARE_LOG_CATEGORY_EXTERN(LogTemp, Log, All);

```

_CoreGlobals.cpp:_

```auto
DEFINE_LOG_CATEGORY(LogTemp);

```

You actually do include the CoreGlobals in any of your headers as long as you `#include "CoreMinimal.h"` which in return includes CoreGlobals.h. Thus, you can use LogTemp anywhere.

The key to being able to use your custom log category in other modules but the one where it is defined in, however, seems to be the CORE\_API directive right before you declare the log temp category. Without it it is not possible to use the log category in another module (Though it might be possible to redefine `DEFINE_LOG_CATEGORY(LogTemp)` in your second module, but that should be avoided I feel).

So your declaration could look like:

_MyLogCategory.h_

```auto
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(LogMyGameLog, Log, All);

```

_MyLogCategory.cpp_

```auto
DEFINE_LOG_CATEGORY(LogMyGameLog);

```

Beware, you still need to include the header, in which the category is defined, in the class where you want to use the category.

_MyCategoryUserInMyOtherModule.cpp_

```auto
#include "MyGame/MyLogCategory.h"

```

AND obviously you need to set up the dependency to the category’s module in the other module where you wanna use it. That happens in the PublicDependencyModuleNames in your _MyOtherModule.Build.cs_.

```auto
PublicDependencyModuleNames.AddRange(new string[] { "Core", "MyGame" });

```

It is possible to define the category in your module’s class, too, such as:

_MyGame.h_

```auto
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(LogMyGameLog, Log, All);

```

_MyGame.cpp_

```auto
DEFINE_LOG_CATEGORY(LogMyGameLog);

```

But you will still need to `#include "MyGame/MyGame.h"` and have the dependency set correctly ofc.

---

<div class="post-metadata">

**Author:** ![VoiDTimo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VoiDTimo](https://forums.unrealengine.com/u/VoiDTimo)\
**Post date:** [October 29, 2024, 8:56am UTC](https://forums.unrealengine.com/t/how-to-declare-log-category-that-can-be-accessed-by-all-classes-like-logtemp/482317/4 "2024-10-29T08:56:54Z")

</div>

Appreciate your greatly helpful reply as this is not noted anywhere.
