File tree Expand file tree Collapse file tree
com.unity.multiplayer.mlapi/Runtime/Logging Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . IO ;
3+
4+ #if DEVELOPMENT_BUILD || UNITY_EDITOR
5+
6+ namespace MLAPI . Logging
7+ {
8+ /// <summary>
9+ /// Helper class for logging
10+ /// Saves to a file identified by the current UTC epoch time. This is useful
11+ /// when debugging what happens on multiple processes on the same machine
12+ /// Only available for debugging on DEVELOPMENT_BUILD or UNITY_EDITOR
13+ /// </summary>
14+ public class FileLogger : IDisposable
15+ {
16+ private static FileLogger m_Instance = null ;
17+ public static FileLogger Instance
18+ {
19+ get
20+ {
21+ if ( m_Instance == null )
22+ {
23+ m_Instance = new FileLogger ( ) ;
24+ }
25+ return m_Instance ;
26+ }
27+ }
28+
29+ private StreamWriter m_Writer ;
30+
31+ private FileLogger ( )
32+ {
33+ m_Writer = new StreamWriter ( "log." + DateTimeOffset . UtcNow . ToUnixTimeSeconds ( ) + ".txt" ) ;
34+ m_Writer . AutoFlush = true ;
35+ }
36+
37+ public void Dispose ( )
38+ {
39+ m_Writer . Dispose ( ) ;
40+ }
41+
42+ /// <summary>
43+ /// Logs a line
44+ /// <param name="line">The line to log to the file for this process</param>
45+ /// </summary>
46+ public void Log ( string line )
47+ {
48+ m_Writer . WriteLine ( line ) ;
49+ }
50+ }
51+ }
52+
53+ #endif
You can’t perform that action at this time.
0 commit comments