Skip to content

Commit c79bf25

Browse files
committed
MirrorInternalLogs: make file log format configurable
1 parent ae92af0 commit c79bf25

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/MirrorInternalLogs/MirrorInternalLogsPatcher.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ internal static class MirrorInternalLogsPatcher
3737
.AppendLine("process - process name")
3838
.ToString());
3939

40+
internal static ConfigEntry<string> LogFormat = Config.Bind("Logging.File", "LogFormat", "[{0}] {1}",
41+
new StringBuilder()
42+
.AppendLine("Format for log messages. Accepts same input as String.Format.")
43+
.AppendLine("Available parameters:")
44+
.AppendLine("0 - Log level as reported by unity")
45+
.AppendLine("1 - The actual log message")
46+
.AppendLine("2 - Current timestamp as DateTime object")
47+
.ToString());
48+
4049
public static IEnumerable<string> TargetDLLs { get; } = new string[0];
4150

4251
public static void Patch(AssemblyDefinition ass)
@@ -95,7 +104,14 @@ private static void InitializeFileLog()
95104

96105
private static void InternalUnityLoggerOnOnUnityInternalLog(object sender, UnityLogEventArgs e)
97106
{
98-
writer.WriteLine($"[{e.LogLevel}] {e.Message.Trim()}");
107+
try
108+
{
109+
writer.WriteLine(LogFormat.Value, e.LogLevel, e.Message.Trim(), DateTime.Now);
110+
}
111+
catch (Exception)
112+
{
113+
// Pass on failed logging
114+
}
99115
}
100116
}
101117
}

0 commit comments

Comments
 (0)