Skip to content

Commit

Permalink
Merge pull request #4940 from peppy/fix-incorrect-conditional-debug
Browse files Browse the repository at this point in the history
Fix incorrect usages of `ConditionalAttribute` for debug isolation
  • Loading branch information
smoogipoo committed Dec 17, 2021
2 parents 08b3069 + 7aa39d0 commit 7d8e6d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
11 changes: 7 additions & 4 deletions osu.Framework/Logging/LoadingComponentsLogger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Diagnostics;
using osu.Framework.Development;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Lists;
Expand All @@ -12,23 +12,26 @@ internal static class LoadingComponentsLogger
{
private static readonly WeakList<Drawable> loading_components = new WeakList<Drawable>();

[Conditional("DEBUG")]
public static void Add(Drawable component)
{
if (!DebugUtils.IsDebugBuild) return;

lock (loading_components)
loading_components.Add(component);
}

[Conditional("DEBUG")]
public static void Remove(Drawable component)
{
if (!DebugUtils.IsDebugBuild) return;

lock (loading_components)
loading_components.Remove(component);
}

[Conditional("DEBUG")]
public static void LogAndFlush()
{
if (!DebugUtils.IsDebugBuild) return;

lock (loading_components)
{
Logger.Log("⏳ Currently loading components");
Expand Down
7 changes: 4 additions & 3 deletions osu.Framework/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using osu.Framework.Platform;
using System.Linq;
using System.Threading;
using osu.Framework.Development;
using osu.Framework.Platform;
using osu.Framework.Statistics;
using osu.Framework.Threading;

Expand Down Expand Up @@ -267,9 +266,11 @@ public static Logger GetLogger(string name)
/// Logs a new message with the <see cref="LogLevel.Debug"/> and will only be logged if your project is built in the Debug configuration. Please note that the default setting for <see cref="Level"/> is <see cref="LogLevel.Verbose"/> so unless you increase the <see cref="Level"/> to <see cref="LogLevel.Debug"/> messages printed with this method will not appear in the output.
/// </summary>
/// <param name="message">The message that should be logged.</param>
[Conditional("DEBUG")]
public void Debug(string message = @"")
{
if (!DebugUtils.IsDebugBuild)
return;

Add(message, LogLevel.Debug);
}

Expand Down

0 comments on commit 7d8e6d0

Please sign in to comment.