Keen's logs now go to Logs/Keen-*

Various formatting options
This commit is contained in:
Westin Miller
2017-10-27 14:13:56 -07:00
parent 4d0dcede41
commit fdc20d4e9d
2 changed files with 26 additions and 34 deletions

View File

@@ -2,14 +2,21 @@
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" />
<variable name="logContent" value="${message:withException=true}"/>
<targets> <targets>
<target xsi:type="File" name="main" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" fileName="Logs\Torch-${shortdate}.log" /> <target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
<target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" />
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" /> <target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
<target xsi:type="ColoredConsole" name="console" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" /> <target xsi:type="ColoredConsole" name="console" layout="${var:logStamp} ${logger}: ${var:logContent}" />
<target xsi:type="File" name="patch" layout="${message}" fileName="Logs\patch.log"/> <target xsi:type="File" name="patch" layout="${var:logContent}" fileName="Logs\patch.log"/>
</targets> </targets>
<rules> <rules>
<logger name="Keen" minlevel="Info" writeTo="console"/>
<logger name="Keen" minlevel="Debug" writeTo="keen" final="true" />
<logger name="*" minlevel="Info" writeTo="main, console" /> <logger name="*" minlevel="Info" writeTo="main, console" />
<logger name="Chat" minlevel="Info" writeTo="chat" /> <logger name="Chat" minlevel="Info" writeTo="chat" />
<!--<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>--> <!--<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>-->

View File

@@ -13,14 +13,12 @@ using VRage.Utils;
namespace Torch.Managers namespace Torch.Managers
{ {
public class KeenLogManager : Manager [PatchShim]
internal class KeenLogManager
{ {
private static readonly Logger _log = LogManager.GetLogger("Keen"); private static readonly Logger _log = LogManager.GetLogger("Keen");
#pragma warning disable 649 #pragma warning disable 649
[Dependency]
private PatchManager.PatchManager _patchManager;
[ReflectedMethodInfo(typeof(MyLog), nameof(MyLog.Log), Parameters = new[] { typeof(MyLogSeverity), typeof(StringBuilder) })] [ReflectedMethodInfo(typeof(MyLog), nameof(MyLog.Log), Parameters = new[] { typeof(MyLogSeverity), typeof(StringBuilder) })]
private static MethodInfo _logStringBuilder; private static MethodInfo _logStringBuilder;
@@ -45,35 +43,22 @@ namespace Torch.Managers
[ReflectedMethodInfo(typeof(MyLog), nameof(MyLog.WriteLineAndConsole), Parameters = new[] { typeof(string) })] [ReflectedMethodInfo(typeof(MyLog), nameof(MyLog.WriteLineAndConsole), Parameters = new[] { typeof(string) })]
private static MethodInfo _logWriteLineAndConsole; private static MethodInfo _logWriteLineAndConsole;
#pragma warning restore 649 #pragma warning restore 649
private PatchContext _context; public static void Patch(PatchContext context)
public KeenLogManager(ITorchBase torchInstance) : base(torchInstance)
{ {
} context.GetPattern(_logStringBuilder).Prefixes.Add(Method(nameof(PrefixLogStringBuilder)));
context.GetPattern(_logFormatted).Prefixes.Add(Method(nameof(PrefixLogFormatted)));
public override void Attach() context.GetPattern(_logWriteLine).Prefixes.Add(Method(nameof(PrefixWriteLine)));
{ context.GetPattern(_logAppendToClosedLog).Prefixes.Add(Method(nameof(PrefixAppendToClosedLog)));
_context = _patchManager.AcquireContext(); context.GetPattern(_logWriteLineAndConsole).Prefixes.Add(Method(nameof(PrefixWriteLineConsole)));
_context.GetPattern(_logStringBuilder).Prefixes.Add(Method(nameof(PrefixLogStringBuilder))); context.GetPattern(_logWriteLineException).Prefixes.Add(Method(nameof(PrefixWriteLineException)));
_context.GetPattern(_logFormatted).Prefixes.Add(Method(nameof(PrefixLogFormatted))); context.GetPattern(_logAppendToClosedLogException).Prefixes.Add(Method(nameof(PrefixAppendToClosedLogException)));
_context.GetPattern(_logWriteLine).Prefixes.Add(Method(nameof(PrefixWriteLine))); context.GetPattern(_logWriteLineOptions).Prefixes.Add(Method(nameof(PrefixWriteLineOptions)));
_context.GetPattern(_logAppendToClosedLog).Prefixes.Add(Method(nameof(PrefixAppendToClosedLog)));
_context.GetPattern(_logWriteLineAndConsole).Prefixes.Add(Method(nameof(PrefixWriteLineConsole)));
_context.GetPattern(_logWriteLineException).Prefixes.Add(Method(nameof(PrefixWriteLineException)));
_context.GetPattern(_logAppendToClosedLogException).Prefixes.Add(Method(nameof(PrefixAppendToClosedLogException)));
_context.GetPattern(_logWriteLineOptions).Prefixes.Add(Method(nameof(PrefixWriteLineOptions)));
_patchManager.Commit();
}
public override void Detach()
{
_patchManager.FreeContext(_context);
} }
private static MethodInfo Method(string name) private static MethodInfo Method(string name)
@@ -96,7 +81,7 @@ namespace Torch.Managers
private static bool PrefixWriteLine(MyLog __instance, string msg) private static bool PrefixWriteLine(MyLog __instance, string msg)
{ {
_log.Trace(PrepareLog(__instance).Append(msg)); _log.Debug(PrepareLog(__instance).Append(msg));
return false; return false;
} }
@@ -120,13 +105,13 @@ namespace Torch.Managers
private static bool PrefixAppendToClosedLogException(Exception e) private static bool PrefixAppendToClosedLogException(Exception e)
{ {
_log.Info(e); _log.Error(e);
return false; return false;
} }
private static bool PrefixWriteLineException(Exception ex) private static bool PrefixWriteLineException(Exception ex)
{ {
_log.Info(ex); _log.Error(ex);
return false; return false;
} }