Browse Source

Added a rate limiter of sorts to StandardLogger

Changed config name
pull/1/head
DaNike 5 years ago
parent
commit
9e111136be
3 changed files with 37 additions and 7 deletions
  1. +0
    -1
      .gitignore
  2. +5
    -6
      IPA.Loader/Config/SelfConfig.cs
  3. +32
    -0
      IPA.Loader/Logging/StandardLogger.cs

+ 0
- 1
.gitignore View File

@ -250,6 +250,5 @@ paket-files/
# JetBrains Rider # JetBrains Rider
.idea/ .idea/
*.sln.iml *.sln.iml
/MigrationBackup/d2a2abe6/IPA.Injector
/bsinstalldir.txt /bsinstalldir.txt
/.wiki /.wiki

+ 5
- 6
IPA.Loader/Config/SelfConfig.cs View File

@ -17,11 +17,10 @@ namespace IPA.Config
value.Load(); value.Load();
SelfConfigRef = value.MakeLink<SelfConfig>((c, v) => SelfConfigRef = value.MakeLink<SelfConfig>((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; _loaderConfig = value;
} }
@ -31,10 +30,10 @@ namespace IPA.Config
public static void Set() 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"; internal const string IPA_Version = "3.12.0";
public bool Regenerate = true; public bool Regenerate = true;


+ 32
- 0
IPA.Loader/Logging/StandardLogger.cs View File

@ -183,6 +183,8 @@ namespace IPA.Logging
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;
private static StandardLogger loggerLogger;
/// <summary> /// <summary>
/// The log printer thread for <see cref="StandardLogger"/>. /// The log printer thread for <see cref="StandardLogger"/>.
/// </summary> /// </summary>
@ -193,6 +195,9 @@ namespace IPA.Logging
StopLogThread(); StopLogThread();
}; };
loggerLogger = new StandardLogger("Log Subsystem");
loggerLogger.printers.Clear();
var started = new HashSet<LogPrinter>(); var started = new HashSet<LogPrinter>();
while (logQueue.TryTake(out var msg, Timeout.Infinite)) while (logQueue.TryTake(out var msg, Timeout.Infinite))
{ {
@ -227,6 +232,33 @@ namespace IPA.Logging
Console.WriteLine($"printer errored: {e}"); 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<LogPrinter>(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 // wait for messages for 500ms before ending the prints
while (logQueue.TryTake(out msg, TimeSpan.FromMilliseconds(500))); while (logQueue.TryTake(out msg, TimeSpan.FromMilliseconds(500)));


Loading…
Cancel
Save