Outputting debug messages
Using logs in programming has several benefits. Firstly, it can help developers to trace runtime information and use the clues to troubleshoot problems. Secondly, developers can also use logs to track and fix dynamic runtime errors that are usually difficult to identify during static debugging. Finally, logs can be used to monitor program running states for analyzing and improving performance, security, and quality. Logs are an essential tool for developers.
Here, we will introduce two ways through which you can output debug messages in Unreal: the UE_LOG
macro and the AddOnScreenDebugMessage
function.
Using the UE_LOG macro
UE_LOG
is a macro that logs messages to either the Output Log window, the Console, or the log files. Use the tilde key (~) to open and close the console.
Figure 9.6 – UE5 editor Output Log window
The syntax of UE_LOG
is as follows:
UE_LOG(<LogType>, <LogLevel>, <Message>...