From 154ef2344b97f34df68d67c5b3cdbfe7844e081c Mon Sep 17 00:00:00 2001 From: DaNike Date: Sat, 26 Jan 2019 14:41:51 -0600 Subject: [PATCH] Added a rate limiter of sorts to StandardLogger Changed config name --- .gitignore | 1 - IPA.Loader/Config/SelfConfig.cs | 11 +++++----- IPA.Loader/Logging/StandardLogger.cs | 32 ++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 1cde24bd..5faf71bf 100644 --- a/.gitignore +++ b/.gitignore @@ -250,6 +250,5 @@ paket-files/ # JetBrains Rider .idea/ *.sln.iml -/MigrationBackup/d2a2abe6/IPA.Injector /bsinstalldir.txt /.wiki diff --git a/IPA.Loader/Config/SelfConfig.cs b/IPA.Loader/Config/SelfConfig.cs index 80f87b37..24fbfe02 100644 --- a/IPA.Loader/Config/SelfConfig.cs +++ b/IPA.Loader/Config/SelfConfig.cs @@ -17,11 +17,10 @@ namespace IPA.Config value.Load(); SelfConfigRef = value.MakeLink((c, v) => { - var val = v.Value; - if (val.Regenerate) - c.Store(val = new SelfConfig { Regenerate = false }); + if (v.Value.Regenerate) + c.Store(v.Value = new SelfConfig { Regenerate = false }); - StandardLogger.Configure(val); + StandardLogger.Configure(v.Value); }); _loaderConfig = value; } @@ -31,10 +30,10 @@ namespace IPA.Config public static void Set() { - LoaderConfig = Config.GetProviderFor(Path.Combine("UserData", IPA_Name), "toml", "json"); + LoaderConfig = Config.GetProviderFor(Path.Combine("UserData", IPA_Name), "json"); } - internal const string IPA_Name = "Beat Saber IPA - Builtin manifest support"; + internal const string IPA_Name = "Beat Saber IPA"; internal const string IPA_Version = "3.12.0"; public bool Regenerate = true; diff --git a/IPA.Loader/Logging/StandardLogger.cs b/IPA.Loader/Logging/StandardLogger.cs index 78dcfd64..996e459c 100644 --- a/IPA.Loader/Logging/StandardLogger.cs +++ b/IPA.Loader/Logging/StandardLogger.cs @@ -183,6 +183,8 @@ namespace IPA.Logging private static readonly BlockingCollection logQueue = new BlockingCollection(); private static Thread logThread; + private static StandardLogger loggerLogger; + /// /// The log printer thread for . /// @@ -193,6 +195,9 @@ namespace IPA.Logging StopLogThread(); }; + loggerLogger = new StandardLogger("Log Subsystem"); + loggerLogger.printers.Clear(); + var started = new HashSet(); while (logQueue.TryTake(out var msg, Timeout.Infinite)) { @@ -227,6 +232,33 @@ namespace IPA.Logging Console.WriteLine($"printer errored: {e}"); } } + + if (logQueue.Count > 512) + { + loggerLogger.printers.Clear(); + printers = new LogPrinter[0]; + // clear the queue + while (logQueue.TryTake(out var message)) + { + var messageLogger = message.Logger; + printers = printers.Concat(messageLogger.printers); + do + { + messageLogger = messageLogger.parent; + if (messageLogger != null) + printers = printers.Concat(messageLogger.printers); + } while (messageLogger != null); + } + // HashSet-ify to make the elements unique + loggerLogger.printers.AddRange(new HashSet(printers)); + logQueue.Add(new LogMessage + { + Level = Level.Warning, + Logger = loggerLogger, + Message = "Messages omitted to improve performance", + Time = DateTime.Now + }); + } } // wait for messages for 500ms before ending the prints while (logQueue.TryTake(out msg, TimeSpan.FromMilliseconds(500)));