Logging

You can log information about your game while it runs using Log.

Unlike , which retrieves information automatically, it's up to you to create your own log messages and define when they're triggered. For example, you can create a log message that triggers when a character performs a certain action. This is useful to investigate how your game is performing.

Note

Logging is disabled when you build the game in release mode.

When you use logging and run your game in debug mode, Xenko opens a console in a second window to display logging information. The messages are color-coded by level. The name of the module (such as the script containing the log message) is displayed in brackets. This is followed by the log level (eg Warning, Error, etc), then the log message.

If you run your game from Visual Studio, log messages are shown in the Visual Studio Output window instead.

Log output window

There are six levels of log message, used for different levels of severity.

By default, the log displays messages for the level Info and higher. This means it doesn't display Debug or Verbose messages. To change this, see Set the minimum level below.

In the script containing code you want to log, write:

You can combine this with if statements to log this message under certain conditions (see Example script below).

You can set a minimum log level to display. For example, if you only want to see messages as severe as Warning or higher, use:

    Note

    This isn't a global setting. The log level you set only applies to the script you set it in.

    1. // Disables logging of the RouterClient module

    To save the log output to a text file, add this code to the Start method:

    1. GlobalLogger.GlobalMessageLogged += fileWriter;

    This creates a file in the Debug folder of your project (eg MyGame\MyGame\Bin\Windows\Debug\myLogFile.txt).