Why are many Unity logs not routed through Debug.unityLogger.logHandler?

I am trying to route all logs into a custom file in order to gain more control over the retention period of log files. This includes my own logs as well as the official Unity logs.

For that I am overwriting Debug.unityLogger.logHandler with a custom implementation. The problem is that many Unity logs are not routed through this custom logger and end up in Player.log (however some Unity logs are routed through my logger).

Does unity often bypass Debug.unityLogger.logHandler and write to their log file directly?

From the documentation I would assume that I should get all logs handed to me so that I can prevent them from being logged to the default Player.log and into my own file instead. Instead logs are now distributed into my custom file as well as the official Player.log.

These are some of the Unity logs that bypass my custom logger:

The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script (FogCullVolume) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'NoFog apartment (4)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog (4)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog apartment (3)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog') is missing!
The referenced script on this Behaviour (Game Object 'NoFog (3)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog (2)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog (1)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog apartment (1)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog (1)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog apartment (2)') is missing!
The referenced script on this Behaviour (Game Object 'NoFog') is missing!
Unloading 16 Unused Serialized files (Serialized files now loaded: 0)
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
The tree Prefab_Grass_v2_withFlowers couldn't be instanced because one of the materials is missing.
UnloadTime: 1.768800 ms
Unloading 4 unused Assets to reduce memory usage. Loaded Objects now: 117136.
Total: 16.449500 ms (FindLiveObjects: 4.966700 ms CreateObjectMapping: 1.292800 ms MarkObjects: 10.101600 ms  DeleteObjects: 0.088200 ms)

[Physics::Module] Cleanup current backned.
[Physics::Module] Id: 0xf2b8ea05
Internal: There are remaining Allocations on the JobTempAlloc. This is a leak, and will impact performance
To Debug, run app with -diag-job-temp-memory-leak-validation cmd line argument. This will output the callstacks of the leaked allocations.

And here is an example of an official log entry that I receive through the logger:

RenderGraph is now enabled.

The only thing that consistently works are my own Debug.Log statements which are always routed through my own logger.

All logging done using the public methods in the Debug class are routed to the log handler, but there are also a bunch of internal methods with the parameter list (string message, string fileName, int lineNumber, int columnNumber) that are not. I don’t think there’s any way to get internal logging that is done using those to be routed to the log handler.

You can receive callbacks when these internal messages are logged as well by subscribing to the Application.logMessageReceivedThreaded event, for what it’s worth.

1 Like