Logging

Custom logging was added in the form of MACROS to make the logging more user friendly and to give us the ability to enable or disable certain logging during debugging. The MACROS are placed in theRTSPCH.h/cpp files and are globally available. In order to toggle the logging categories on/off, enter the command "Log TheLogCategory" in the command line.


Unreal logging uses logging categories and verbosity levels. Every system should have its own logging category. For example, a Fortress could have its own category named FortressBuilding. In the log files, you would then see that every message logged by the Fortress, starts with "FortressBuilding: ...". This makes it clear what messages belong together.

In total, there are 7 verbosity levels:

Verbosity LevelPrinted in Console?Printed in Editor's Log?Notes
FatalYesN/ACrashes the session, even if logging is disabled
ErrorYesYesLog text is coloured red
WarningYesYesLog text is coloured yellow
DisplayYesYesLog text is coloured grey
LogNoYesLog text is coloured grey
VerboseNoNo
VeryVerboseNoNo

If you want some more information about logging, read the following Wiki page.

1. Default logging

The new default logging MACROS are:

  • LOG_INFO
  • LOG_WARNING
  • LOG_ERROR

which respectively log Default, Warning and Error messages to our custom default logging category named LogDefault. These log messages will by default also log the name of the function in which the logging took place. An example on how to use them:

LOG_INFO("%d?! That's not bad for a pointy-eared Elvish princeling.", 42);

As you can see, you just make your message the same way as you would with the UE4 logging system.

2. Conditional Logging

Conditional logging was also added. The default conditional log MACROS are:

  • CLOG_INFO
  • CLOG_WARNING
  • CLOG_ERROR

Another example on how to use them:

CLOG_WARNING( 
    bHadFirstBreakfast, 
    "We've had one, yes. What about second %s?", 
    *BreakFast->GetName()
);

This will only log if the first argument, the condition, is true.

3. Making new categories

Go to the RTSPCH.h/cpp files to make new logging categories. In here, you will find commented examples, which you can copy, paste and change with your new category.

  • You should declare your new category in RTSPCH.h with DECLARE_LOG_CATEGORY_EXTERN(PutYourCategoryHere, DefaultVerbosity, CompileTimeVerbosity);
  • You should initialize your new category in RTSPCH.cpp with DEFINE_LOG_CATEGORY(PutYourCategoryHere);
  • Define your new MACROS in RTSPCH.h.