Search Unity

Question Is it possible to disable Debug.Log in Burst compiled code?

Discussion in 'Burst' started by mbaker, May 13, 2022.

  1. mbaker

    mbaker

    Joined:
    Jan 9, 2013
    Posts:
    52
    I'm working on adding burst support for an existing debug logger that we have developed. I'd like to intercept Debug.Log messages from Burst compiled code, decorate the message, and pipe it through our logging system.

    I've been able to listen for log messages emitted from burst compiled code but have been unable to prevent the default log message from showing up.

    What I've discovered so far is that log messages emitted from burst compiled code:
    - Don't pass through Debug.unityLogger.logHandler - So implementing and assigning a custom ILogHandler implementation doesn't help.
    - Aren't affected by Debug.unityLogger.logEnabled - Setting this to false only suppresses log messages from outside a burst context.
    - Do trigger Application.logMessageReceivedThreaded events - This event triggers before the default message makes it to the console but there doesn't appear to be a mechanism to stop the message from being logged.

    I poked around the BurstRuntime and BurstCompilerService types. I see what looks like the outgoing method calls but no way to disable log messages from a burst context.

    Is there a way to suppress Debug.Log messages from Burst compiled code?
     
  2. vectorized-runner

    vectorized-runner

    Joined:
    Jan 22, 2018
    Posts:
    398
    Why use Debug.Log at all if you're building your own log system? Just call your own log methods
     
  3. mbaker

    mbaker

    Joined:
    Jan 9, 2013
    Posts:
    52
    Pulling in Debug.Log messages allows us to include messages from 3rd party code, including those from the Entities package, in our logging. By piping log messages through our logging system it allows us to capture those logs for different output targets (server, file, unity console, etc..) and reformat/decorate them with more contextual information.

    We can also send messages directly to our logging system with more options/features available to the developer. That's our preferred method of logging in application specific code.
     
    Shinyclef likes this.