Daily Unreal Column #28 - Log category as a struct
We all know what log category is and how to use it when logging things to the output log. But, did you know that the log category is actually a struct and has it's own properties?
If we take a look at what the DECLARE_LOG_CATEGORY_EXTERN
macro implementation we can see it's actually making a declaration of a struct:
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity) \
extern struct FLogCategory##CategoryName : public FLogCategory<ELogVerbosity::DefaultVerbosity, ELogVerbosity::CompileTimeVerbosity> \
{ \
FORCEINLINE FLogCategory##CategoryName() : FLogCategory(TEXT(#CategoryName)) {} \
} CategoryName;
and... The struct inherits from FLogCategory
and further down from the FLogCategoryBase
.
This means that you can use the defined struct just like any other property. For example, you can check whether this category logs should be suppressed or not by calling:
if (LogTemp.IsSuppressed(ELogVerbosity::Verbose))
{
// Do stuff
}