|
@ -106,6 +106,7 @@ namespace IPA.Logging |
|
|
/// <value>the global filter level</value>
|
|
|
/// <value>the global filter level</value>
|
|
|
public static LogLevel PrintFilter { get; internal set; } = LogLevel.All; |
|
|
public static LogLevel PrintFilter { get; internal set; } = LogLevel.All; |
|
|
private static bool showTrace = false; |
|
|
private static bool showTrace = false; |
|
|
|
|
|
private static volatile bool syncLogging = false; |
|
|
|
|
|
|
|
|
private readonly List<LogPrinter> printers = new List<LogPrinter>(); |
|
|
private readonly List<LogPrinter> printers = new List<LogPrinter>(); |
|
|
private readonly StandardLogger parent; |
|
|
private readonly StandardLogger parent; |
|
@ -120,6 +121,7 @@ namespace IPA.Logging |
|
|
showSourceClass = SelfConfig.Debug_.ShowCallSource_; |
|
|
showSourceClass = SelfConfig.Debug_.ShowCallSource_; |
|
|
PrintFilter = SelfConfig.Debug_.ShowDebug_ ? LogLevel.All : LogLevel.InfoUp; |
|
|
PrintFilter = SelfConfig.Debug_.ShowDebug_ ? LogLevel.All : LogLevel.InfoUp; |
|
|
showTrace = SelfConfig.Debug_.ShowTrace_; |
|
|
showTrace = SelfConfig.Debug_.ShowTrace_; |
|
|
|
|
|
syncLogging = SelfConfig.Debug_.SyncLogging_; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private StandardLogger(StandardLogger parent, string subName) |
|
|
private StandardLogger(StandardLogger parent, string subName) |
|
@ -200,13 +202,23 @@ namespace IPA.Logging |
|
|
logWaitEvent.Wait(); |
|
|
logWaitEvent.Wait(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
|
|
|
var sync = syncLogging && !IsOnLoggerThread; |
|
|
|
|
|
if (sync) |
|
|
|
|
|
{ |
|
|
|
|
|
threadSync ??= new ManualResetEventSlim(); |
|
|
|
|
|
threadSync.Reset(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
logQueue.Add(new LogMessage |
|
|
logQueue.Add(new LogMessage |
|
|
{ |
|
|
{ |
|
|
Level = level, |
|
|
Level = level, |
|
|
Message = message, |
|
|
Message = message, |
|
|
Logger = this, |
|
|
Logger = this, |
|
|
Time = Utils.CurrentTime() |
|
|
|
|
|
|
|
|
Time = Utils.CurrentTime(), |
|
|
|
|
|
Sync = threadSync |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (sync) threadSync.Wait(); |
|
|
} |
|
|
} |
|
|
catch (InvalidOperationException) |
|
|
catch (InvalidOperationException) |
|
|
{ |
|
|
{ |
|
@ -214,6 +226,9 @@ namespace IPA.Logging |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[ThreadStatic] |
|
|
|
|
|
private static ManualResetEventSlim threadSync; |
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
/// <inheritdoc />
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// An override to <see cref="M:IPA.Logging.Logger.Debug(System.String)" /> which shows the method that called it.
|
|
|
/// An override to <see cref="M:IPA.Logging.Logger.Debug(System.String)" /> which shows the method that called it.
|
|
@ -248,9 +263,14 @@ namespace IPA.Logging |
|
|
public StandardLogger Logger; |
|
|
public StandardLogger Logger; |
|
|
public string Message; |
|
|
public string Message; |
|
|
public DateTime Time; |
|
|
public DateTime Time; |
|
|
|
|
|
public ManualResetEventSlim Sync; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static ManualResetEventSlim logWaitEvent = new ManualResetEventSlim(true); |
|
|
|
|
|
|
|
|
[ThreadStatic] |
|
|
|
|
|
private static bool? isOnLoggerThread = null; |
|
|
|
|
|
public static bool IsOnLoggerThread => isOnLoggerThread ??= Thread.CurrentThread.ManagedThreadId == logThread.ManagedThreadId; |
|
|
|
|
|
|
|
|
|
|
|
private static readonly ManualResetEventSlim logWaitEvent = new ManualResetEventSlim(true); |
|
|
private static readonly BlockingCollection<LogMessage> logQueue = new BlockingCollection<LogMessage>(); |
|
|
private static readonly BlockingCollection<LogMessage> logQueue = new BlockingCollection<LogMessage>(); |
|
|
private static Thread logThread; |
|
|
private static Thread logThread; |
|
|
|
|
|
|
|
@ -314,6 +334,8 @@ namespace IPA.Logging |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
msg.Sync?.Set(); |
|
|
|
|
|
|
|
|
var debugConfig = SelfConfig.Instance?.Debug; |
|
|
var debugConfig = SelfConfig.Instance?.Debug; |
|
|
|
|
|
|
|
|
if (debugConfig != null && debugConfig.HideMessagesForPerformance |
|
|
if (debugConfig != null && debugConfig.HideMessagesForPerformance |
|
@ -337,6 +359,8 @@ namespace IPA.Logging |
|
|
foreach (var print in messageLogger.printers) |
|
|
foreach (var print in messageLogger.printers) |
|
|
prints.Add(print); |
|
|
prints.Add(print); |
|
|
} while (messageLogger != null); |
|
|
} while (messageLogger != null); |
|
|
|
|
|
|
|
|
|
|
|
message.Sync?.Set(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// print using logging subsystem to all logger printers
|
|
|
// print using logging subsystem to all logger printers
|
|
|