Skip to content

Commit

Permalink
MirrorInternalLogs: make file log format configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ghorsington committed Aug 5, 2020
1 parent ae92af0 commit c79bf25
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/MirrorInternalLogs/MirrorInternalLogsPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ internal static class MirrorInternalLogsPatcher
.AppendLine("process - process name")
.ToString());

internal static ConfigEntry<string> LogFormat = Config.Bind("Logging.File", "LogFormat", "[{0}] {1}",
new StringBuilder()
.AppendLine("Format for log messages. Accepts same input as String.Format.")
.AppendLine("Available parameters:")
.AppendLine("0 - Log level as reported by unity")
.AppendLine("1 - The actual log message")
.AppendLine("2 - Current timestamp as DateTime object")
.ToString());

public static IEnumerable<string> TargetDLLs { get; } = new string[0];

public static void Patch(AssemblyDefinition ass)
Expand Down Expand Up @@ -95,7 +104,14 @@ private static void InitializeFileLog()

private static void InternalUnityLoggerOnOnUnityInternalLog(object sender, UnityLogEventArgs e)
{
writer.WriteLine($"[{e.LogLevel}] {e.Message.Trim()}");
try
{
writer.WriteLine(LogFormat.Value, e.LogLevel, e.Message.Trim(), DateTime.Now);
}
catch (Exception)
{
// Pass on failed logging
}
}
}
}

0 comments on commit c79bf25

Please sign in to comment.