Custom log categories
One of the first things I set up in a new project, is my custom project log categories. I never knew how useful these would be before I actually started using them. It’s a great debugging tool!
And believe me, the faster you make this a habit, the faster you’ll solve your problems. It takes absulutely no time to set this up, but it’ll save you time in the long run.
Setup
Declare the log channels in the header file (e.g. MyGameLogChannels.h).
MyGameLogChannels.h
#pragma once
#include "Logging/LogMacros.h"
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(LogMyGame, Log, All);
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(LogMyGameNetwork, Log, All);
MYGAME_API DECLARE_LOG_CATEGORY_EXTERN(LogMyGameFrontend, Log, All);
// and more if needed
Define the log categories in the C++ file (e.g. MyGameLogChannel.cpp)
MyGameLogChannels.cpp
#include "MyGameLogChannels.h"
DEFINE_LOG_CATEGORY(LogMyGame);
DEFINE_LOG_CATEGORY(LogMyGameNetwork);
DEFINE_LOG_CATEGORY(LogMyGameFrontend);
Usage
Use the log channels in any class by simplt including MyGameLogChannels.h.
MyCustomActor.cpp
#include "MyGameLogChannels.h"
void AMyCustomActor::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogMyGame, Log, TEXT("AMyCustomActor::BeginPlay started..."));
//...
}