The Log Class

This page describes the Log class, which is the main class used for logging.

The Log class is a static class that is used to log various messages, such as info, warnings, errors, assertions, debugs, and fatals, to the console. It provides methods to log these messages, as well as several settings, tags, and file options to configure the logging behavior.

Here's a brief overview of the logging methods available in the Log class:

  • Info(string message, string tag): Logs an information message to the console.

  • Warn(string message, string tag): Logs a warning message to the console.

  • Error(string message, string tag): Logs an error message to the console.

  • Assert(bool condition, string message, string tag): Logs an assertion message to the console.

  • Debug(string message, string tag): Logs a debug message to the console.

  • Fatal(string message, string tag): Logs a fatal error message to the console.

    • The Fatal log method also has a quit parameter which, when set to true, will quit the application. The quit parameter is optional and its default value is true. This means that if you don't specify the quit parameter, the application will quit after the Fatal message is logged. If you set it to false, the Fatal method will throw an exception instead of quitting the application.

It is important to note that these methods are only a small part of what the Log class offers. The Log class provides several options to configure the logging behavior, including settings, tags, and file options. These options allow developers to tailor the logging output to their specific needs and requirements.

Check out the Settings section for more information about what you can customize:

Properties

  • Settings.DateFormat: (string) The time format for all types of logs.

  • Settings.IsEditor: (bool) If inside the Unity Editor.

  • Settings.InfoEnabled: (bool) If info logs should be enabled.

  • Settings.WarningsEnabled: (bool) If warning logs should be enabled.

  • Settings.ErrorsEnabled: (bool) If error logs should be enabled.

  • Settings.AssertionsEnabled: (bool) If assertion logs should be enabled.

  • Settings.DebugsEnabled: (bool) If debug logs should be enabled.

  • Settings.FatalsEnabled: (bool) If fatal logs should be enabled.

Properties within Settings.Actions:

  • Settings.Actions.InfoLogAction: (Action<string, string, int>) The action that will be used to log an information log to the console.

  • Settings.Actions.WarningLogAction: (Action<string, string, int>) The action that will be used to log a warning log to the console.

  • Settings.Actions.ErrorLogAction: (Action<string, string, int>) The action that will be used to log an error log.

  • Settings.Actions.AssertLogAction: (Action<string, string, int>) The action that will be used to log assertion logs.

  • Settings.Actions.DebugLogAction: (Action<string, string, int>) The action that will be used to log debug logs.

  • Settings.Actions.FatalLogAction: (Action<string, string, int>) The action that will be used to log fatal logs.

Properties within Settings.Tags:

  • Settings.Tags.FatalTag: (string) The prefix for fatal logs.

  • Settings.Tags.ErrorTag: (string) The prefix for error logs.

  • Settings.Tags.WarningTag: (string) The prefix for warning logs.

  • Settings.Tags.InfoTag: (string) The prefix for info logs.

  • Settings.Tags.DebugTag: (string) The prefix for debug logs.

  • Settings.Tags.AssertTag: (string) The prefix for assertion logs.

Properties within Settings.Files:

  • Settings.Files.MaxFileSize: (long) The maximum allowed file size. Defaults to 100 MB.

  • Settings.Files.LogFilesDirectory: (string) The absolute directory for all log files.

Last updated