Log Level Settings
Last updated
Last updated
Any existing logger has defined log levels, that determine the severity and type of log, providing further context that is not required in the log message.
The Logging Toolkit provides a way to fully create and customize any additional log levels that may be relevant to the project.
This page will describe how to configure log levels and how to use them in any of the available loggers.
Disclaimer: Do not manually edit the LogLevelSettings ScriptableObject. The 3 default levels are mandatory and any unexpected change might result in the toolkit to behave abnormally.
In the project settings, the developer can add new log levels and edit existing ones. Here are the available configuration fields:
Field | Type | Description |
---|---|---|
|
| Name for the log level. |
|
| Determines the severity of the log level. This can be used to filter and order log levels. |
|
| Assigns a color to the log level. Used in Log Formatting. |
|
| Enables or disables stack trace inclusion in the log message. |
Creating a log level, can be as simple as including it in the Project Settings. But there are ways to enhance the integration of this new log level into the project.
This section will outline to completely create a new log level. As a use case, let's create the 'Trace' log level.
Add the Log Level to the Project Settings and configure it accordingly.
When logging, call the base Log method, passing the name of the log level:
Note that if the passed value for the log level doesn't exist, a Warning will be thrown and the log call will be discarded.
Results
And that's about it. These are the minimum steps to add a new Log Level, however, the tool provides a way to enhance the integration of this new level with the existing tools. s
Create a new script called LoggingServiceExtensions
.
Add a static extension method for the interface ILoggingService
, as follows:
Note: Feel free to add the [HideInCallstack] attribute, to hide this method from the stack trace.
Now, the logging call for the log level Trace can be called directly from any of the existing logger types - GlobalLogger, GameObjectLogger and ClassLogger: