1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Merge pull request #1745 from peppy/notification-verbosity

Rate limit logged errors displayed as notifications
This commit is contained in:
Dan Balasescu 2017-12-27 15:37:14 +09:00 committed by GitHub
commit 9841fd6cd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 14 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -16,6 +17,15 @@ namespace osu.Game.Tests.Visual
private readonly NotificationOverlay manager; private readonly NotificationOverlay manager;
private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>(); private readonly List<ProgressNotification> progressingNotifications = new List<ProgressNotification>();
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(Notification),
typeof(ProgressNotification),
typeof(ProgressCompletionNotification),
typeof(SimpleNotification),
typeof(IHasCompletionTarget),
};
public TestCaseNotificationOverlay() public TestCaseNotificationOverlay()
{ {
progressingNotifications.Clear(); progressingNotifications.Clear();

View File

@ -16,6 +16,7 @@ using osu.Game.Screens;
using osu.Game.Screens.Menu; using osu.Game.Screens.Menu;
using OpenTK; using OpenTK;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Platform; using osu.Framework.Platform;
@ -220,15 +221,7 @@ namespace osu.Game
Depth = -6, Depth = -6,
}, overlayContent.Add); }, overlayContent.Add);
Logger.NewEntry += entry => forwardLoggedErrorsToNotifications();
{
if (entry.Level < LogLevel.Important) return;
notifications.Post(new SimpleNotification
{
Text = $@"{entry.Level}: {entry.Message}"
});
};
dependencies.Cache(settings); dependencies.Cache(settings);
dependencies.Cache(social); dependencies.Cache(social);
@ -290,6 +283,36 @@ namespace osu.Game
Cursor.State = Visibility.Hidden; Cursor.State = Visibility.Hidden;
} }
private void forwardLoggedErrorsToNotifications()
{
int recentErrorCount = 0;
const double debounce = 5000;
Logger.NewEntry += entry =>
{
if (entry.Level < LogLevel.Error || entry.Target == null) return;
if (recentErrorCount < 2)
{
notifications.Post(new SimpleNotification
{
Icon = FontAwesome.fa_bomb,
Text = (recentErrorCount == 0 ? entry.Message : "Subsequent errors occurred and have been logged.") + "\nClick to view log files.",
Activated = () =>
{
Host.Storage.GetStorageForDirectory("logs").OpenInNativeExplorer();
return true;
}
});
}
Interlocked.Increment(ref recentErrorCount);
Scheduler.AddDelayed(() => Interlocked.Decrement(ref recentErrorCount), debounce);
};
}
private Task asyncLoadStream; private Task asyncLoadStream;
private void loadComponentSingleFile<T>(T d, Action<T> add) private void loadComponentSingleFile<T>(T d, Action<T> add)

View File

@ -177,8 +177,7 @@ namespace osu.Game
} }
catch (MigrationFailedException e) catch (MigrationFailedException e)
{ {
Logger.Log((e.InnerException ?? e).ToString(), LoggingTarget.Database, LogLevel.Error); Logger.Error(e.InnerException ?? e, "Migration failed! We'll be starting with a fresh database.", LoggingTarget.Database);
Logger.Log("Migration failed! We'll be starting with a fresh database.", LoggingTarget.Database, LogLevel.Error);
// if we failed, let's delete the database and start fresh. // if we failed, let's delete the database and start fresh.
// todo: we probably want a better (non-destructive) migrations/recovery process at a later point than this. // todo: we probably want a better (non-destructive) migrations/recovery process at a later point than this.

View File

@ -91,7 +91,6 @@ namespace osu.Game.Overlays.Notifications
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Padding = new MarginPadding Padding = new MarginPadding
{ {
Top = 5,
Left = 45, Left = 45,
Right = 30 Right = 30
}, },

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Edit
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Log($"Could not load this beatmap sucessfully ({e})!", LoggingTarget.Runtime, LogLevel.Error); Logger.Error(e, "Could not load beatmap sucessfully!");
return; return;
} }

View File

@ -125,7 +125,7 @@ namespace osu.Game.Screens.Play
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Log($"Could not load this beatmap sucessfully ({e})!", LoggingTarget.Runtime, LogLevel.Error); Logger.Error(e, "Could not load beatmap sucessfully!");
//couldn't load, hard abort! //couldn't load, hard abort!
Exit(); Exit();