Hi all
I’m developing a project that use a headless build on a linux Google VM that act like a server. Everything works very well, but I would need the server to print the various Debug.Log on the linux console to monitor its operation. I have tried various solutions for this problem, and all of them involve the use of the -logfile command, that should generates a log file in a specific folder where all Debug.Logs are collected.
After several attempts I found two solutions: use -logfile -, which, in theory, should send log messages directly to the console, or -logfile server.log, which generates the log file which in turn can be sent to the console via the tail -f command.
The problem is that in the log file there is no trace of the Debug.Logs launched by the server, but only the normal report generated by unity and by the networking system (Mirror).
You can hook yourself to Unity logs through UnityEngine.Application.logMessageReceived and UnityEngine.Application.logMessageReceivedThreaded made especially for that purpose. The idea was that users would intercept unity logs to build their own mechanism for storing/transmitting logs on the network and on disk, or simply display them. That is because once you are hooked to Unity logs events, you then intercept both Unity native logs, and the logs you emitted through Debug.Log(). An exemple of this here: http://wiki.unity3d.com/index.php/2020/DebugConsole.
Chances are that the logs written on disk with the -logfile command line option do not share the same code path than the logs you perform as one would find out exploring the Unity source files exposed by Unity here: UnityCsReference/Projects/CSharp at master · Unity-Technologies/UnityCsReference · GitHub with the following files:
Runtime\Export\Logging\DebugLogHandler.cs
Runtime\Export\Logging\ILogHandler.cs
Runtime\Export\Logging\ILogger.cs
Runtime\Export\Logging\Logger.cs
Runtime\Export\Logging\UnityLogWriter.bindings.cs
Bonus: Unity are people like you and me. We frequently request features / enhancements. They make common mistakes like the rest of us. Exemple: ask them to replace in UnityLogWritter.binding.cs the following
[ThreadAndSerializationSafe] public static void WriteStringToUnityLog(string s)
{ if (s == null) return; WriteStringToUnityLogImpl(s); }
with the following
[ThreadAndSerializationSafe] public static void WriteStringToUnityLog(string s)
{ if (String.IsNullOrEmpty(s)) return; WriteStringToUnityLogImpl(s); }
They will answer that they include empty strings because of the new line appended for log file text layout and you will have started a discussion, which will prove you they are humans.
Serge Billault.