docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Custom configuration using LoggerConfig

    To customize the logger, use the LoggerConfig object. To use it, you must daisy chain parameters and sinks where each element represents a pipeline stage. Each stage takes as input the output of the previous stage. This means that the order in which you define these stages is important.

    LoggerConfig main pipeline methods

    You can configure most of the stages in the pipeline with the following methods.

    SyncMode

    Use SyncMode to define how to capture the log entries. Either synchronous (FullSync), asynchronously (FullAsync), or using a mix of the two; where only fatal is synchronous while the other levels are asynchronous (FatalIsSynch). This third option is the default one as this offers the best balance between speed and reliability as it ensures that the logger captures the most critical messages before the program crashes.

    MinimumLevel

    Use MinimumLevel to configure the minimal level of the logs for the logger to capture. If you select Debug then the logger captures most logs. If you select Fatal, then the logger captures only fatal level logs.

    OutputTemplate

    Use OutputTemplate to configure what information type the logger captures and how it's displayed. The accepted keywords are:

    • Timestamp: Date and time (UTC)
    • Level: The level of the log entry
    • Message: The actual information that you want to capture
    • Stacktrace: The stack trace where the logger captured the message from.
    • NewLine: Inserts Environment.NewLine.
    • Properties: Reserved keyword.

    The configuration template needs to contain a combination of these keywords surrounded by curly brackets. For example:

    OutputTemplate("{Timestamp} - {Level} - {Message}")
    

    CaptureStacktrace

    Use CaptureStackTrace to define if the current logger should capture the stack trace. This is available within Burst compiled code. If you use a version of Burst prior to 1.80, there might be some missing stack frames.

    RedirectUnityLogs

    Use RedirectUnityLogs to route Debug logs into the package. This is intended as an aid for porting code to the logging package. Debug logs will be sent to all sinks which set this option. All Debug logs will be redirected into the package, overriding any currently configured filtering or enabling of Debug logs.

    Note:

    • Redirection of native logs (logs emitted by the C++ parts of Unity) is only supported in player builds. A current limitation makes this redirection unavailable in the editor. Redirection of logs emitted by C# code is supported both in player builds and in the editor.
    • You will loose context highlighting in the editor when using this feature.

    RetrieveStartupLogs

    Use [RetrieveStartupLogs[(xref:Unity.Logging.LoggerConfig.RetrieveStartupLogs) to retrieve any logs captured before package startup. Logs are only captured when the Player Setting Capture Startup Logs has been set.

    Further information

    • Sinks
    • LoggerConfig API documentation
    In This Article
    • LoggerConfig main pipeline methods
      • SyncMode
      • MinimumLevel
      • OutputTemplate
      • CaptureStacktrace
      • RedirectUnityLogs
      • RetrieveStartupLogs
    • Further information
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)