Skip to content

Commit

Permalink
feat: Use SortedDictionary for LogSettings (#1914)
Browse files Browse the repository at this point in the history
* feat: Use SortedDictionary for LogSettings

* Remove manual sort
  • Loading branch information
MrGadget committed May 21, 2020
1 parent 6c8ff77 commit 7d4c0a9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/Logging/LogFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Mirror
{
public static class LogFactory
{
internal static readonly Dictionary<string, ILogger> loggers = new Dictionary<string, ILogger>();
internal static readonly SortedDictionary<string, ILogger> loggers = new SortedDictionary<string, ILogger>();

public static Dictionary<string, ILogger>.ValueCollection AllLoggers => loggers.Values;
public static SortedDictionary<string, ILogger>.ValueCollection AllLoggers => loggers.Values;

/// <summary>
/// logHandler used for new loggers
Expand Down
7 changes: 2 additions & 5 deletions Assets/Mirror/Runtime/Logging/LogSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct LoggerSettings

public static class LogSettingsExt
{
public static void SaveFromDictionary(this LogSettings settings, Dictionary<string, ILogger> dictionary)
public static void SaveFromDictionary(this LogSettings settings, SortedDictionary<string, ILogger> dictionary)
{
if (settings == null)
{
Expand All @@ -33,15 +33,12 @@ public static void SaveFromDictionary(this LogSettings settings, Dictionary<stri
settings.loglevels.Add(new LogSettings.LoggerSettings { name = kvp.Key, logLevel = kvp.Value.filterLogType });
}

// sort by name so that list is saved in same order each time
settings.loglevels.Sort((x, y) => string.CompareOrdinal(x.name, y.name));

#if UNITY_EDITOR
UnityEditor.EditorUtility.SetDirty(settings);
#endif
}

public static void LoadIntoDictionary(this LogSettings settings, Dictionary<string, ILogger> dictionary)
public static void LoadIntoDictionary(this LogSettings settings, SortedDictionary<string, ILogger> dictionary)
{
if (settings == null)
{
Expand Down

0 comments on commit 7d4c0a9

Please sign in to comment.