Skip to content

Commit

Permalink
fix(LogFactory): fixing clear and find all buttons in log factory
Browse files Browse the repository at this point in the history
find all now just gets field instead of using type name. this fixing types that use string for getLgger instead of a type
  • Loading branch information
James-Frowen committed Dec 31, 2021
1 parent 58422aa commit 6f7e5d5
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Assets/Mirage/Editor/Logging/LogLevelsGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void DrawAllLevelDropdown()

private void DrawGroup(IGrouping<string, LogSettingsSO.LoggerSettings> group)
{
string NameSpace = group.Key ?? "<none>";
string NameSpace = string.IsNullOrEmpty(group.Key) ? "< no namespace >" : group.Key;
if (!folderOutState.ContainsKey(NameSpace))
folderOutState[NameSpace] = false;

Expand Down Expand Up @@ -128,9 +128,11 @@ private void DrawGroup(IGrouping<string, LogSettingsSO.LoggerSettings> group)

private void DrawDeleteAllButton()
{
GUILayout.Label("NOTES: when clearing it might require assembly to be reloaded before the 'find all' button will find everything");
if (GUILayout.Button("Clear All levels"))
{
settings.LogLevels.Clear();
LogFactory.loggers.Clear();
guiChanged = true;
}
}
Expand Down Expand Up @@ -160,8 +162,12 @@ private void DrawFindAllButton()
{
if (field.IsStatic && field.FieldType == typeof(ILogger))
{
// will cause static field to initialize and call GetLogger
// this will get existing or add new logger to factory
var value = (ILogger)field.GetValue(null);
AddIfMissing(type, value);

// we dont then need to add it to factory manually, because the above should have added it
// this is better than adding manually because AddLogger might add using string instead of types full name
}
}
catch (Exception e)
Expand All @@ -171,18 +177,10 @@ private void DrawFindAllButton()
}
}
}
guiChanged = true;
}
}

private void AddIfMissing(Type type, ILogger logger)
{
string fullName = type.FullName;
LogType logType = logger.filterLogType;
bool exist = settings.LogLevels.Any(x => x.FullName == fullName);
if (!exist)
{
settings.LogLevels.Add(new LogSettingsSO.LoggerSettings(fullName, logType));
// refresh so settings list has new items from Factory
checker.Refresh();
guiChanged = true;
}
}

Expand All @@ -194,7 +192,7 @@ private void ApplyAndSaveLevels()
logger.filterLogType = logSetting.logLevel;
}

// tood save outside of editor
// todo save outside of editor
EditorUtility.SetDirty(settings);
}

Expand Down

0 comments on commit 6f7e5d5

Please sign in to comment.