Skip to content

Commit

Permalink
Rename Logger to LoggerAsset, LoggerImpl to Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed May 11, 2024
1 parent fb85140 commit b08ff4c
Show file tree
Hide file tree
Showing 23 changed files with 120 additions and 124 deletions.
6 changes: 3 additions & 3 deletions Editor/UI/Loggers/CompositeLoggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers
/// <summary>
/// Editor GUI for CompositeLogger.
/// </summary>
[CustomEditor(typeof(CompositeLogger))]
[CustomEditor(typeof(CompositeLoggerAsset))]
public class CompositeLoggerEditor : UnityEditor.Editor
{
private static readonly string s_description = L10n.Tr("Description");
Expand All @@ -24,9 +24,9 @@ public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CompositeLogger.description)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CompositeLoggerAsset.description)),
new GUIContent(s_description, s_descriptionTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CompositeLogger.loggers)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(CompositeLoggerAsset.loggerAssets)),
new GUIContent(s_loggers, s_loggersTooltip));

serializedObject.ApplyModifiedProperties();
Expand Down
6 changes: 3 additions & 3 deletions Editor/UI/Loggers/ConsoleLoggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers
/// <summary>
/// Editor GUI for ConsoleLogger.
/// </summary>
[CustomEditor(typeof(ConsoleLogger))]
[CustomEditor(typeof(ConsoleLoggerAsset))]
public class ConsoleLoggerEditor : UnityEditor.Editor
{
private static readonly string s_description = L10n.Tr("Description");
Expand All @@ -24,9 +24,9 @@ public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(ConsoleLogger.description)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(ConsoleLoggerAsset.description)),
new GUIContent(s_description, s_descriptionTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(ConsoleLogger.filterLogType)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(ConsoleLoggerAsset.filterLogType)),
new GUIContent(s_filterLogType, s_filterLogTypeTooltip));

serializedObject.ApplyModifiedProperties();
Expand Down
10 changes: 5 additions & 5 deletions Editor/UI/Loggers/FileLoggerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers
/// <summary>
/// Editor GUI for FileLogger.
/// </summary>
[CustomEditor(typeof(FileLogger))]
[CustomEditor(typeof(FileLoggerAsset))]
public class FileLoggerEditor : UnityEditor.Editor
{
private static readonly string s_description = L10n.Tr("Description");
Expand All @@ -30,13 +30,13 @@ public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLogger.description)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLoggerAsset.description)),
new GUIContent(s_description, s_descriptionTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLogger.outputPath)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLoggerAsset.outputPath)),
new GUIContent(s_outputPath, s_outputPathTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLogger.filterLogType)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLoggerAsset.filterLogType)),
new GUIContent(s_filterLogType, s_filterLogTypeTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLogger.timestamp)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(FileLoggerAsset.timestamp)),
new GUIContent(s_timestamp, s_timestampTooltip));

serializedObject.ApplyModifiedProperties();
Expand Down
2 changes: 1 addition & 1 deletion Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public override void OnInspectorGUI()
new GUIContent(s_timeScale, s_timeScaleTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.junitReportPath)),
new GUIContent(s_junitReportPath, s_junitReportPathTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.logger)),
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.loggerAsset)),
new GUIContent(s_logger, s_loggerTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporter)),
new GUIContent(s_reporter, s_reporterTooltip));
Expand Down
14 changes: 5 additions & 9 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections;
using System.Threading;
using Cysharp.Threading.Tasks;
using DeNA.Anjin.Loggers;
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
using UnityEngine;
Expand All @@ -18,6 +19,7 @@ namespace DeNA.Anjin
/// </summary>
public class Autopilot : MonoBehaviour
{
private AbstractLoggerAsset _loggerAsset;
private ILogger _logger;
private RandomFactory _randomFactory;
private IAgentDispatcher _dispatcher;
Expand All @@ -32,14 +34,8 @@ private void Start()
_settings = _state.settings;
Assert.IsNotNull(_settings);

if (_settings.logger != null)
{
_logger = _settings.logger.LoggerImpl;
}
else
{
_logger = CreateDefaultLogger();
}
_loggerAsset = _settings.loggerAsset;
_logger = _loggerAsset != null ? _loggerAsset.Logger : CreateDefaultLogger();

if (!int.TryParse(_settings.randomSeed, out var seed))
{
Expand Down Expand Up @@ -99,7 +95,7 @@ private void OnDestroy()

_dispatcher?.Dispose();
_logMessageHandler?.Dispose();
_settings.logger?.Dispose();
_settings.loggerAsset?.Dispose();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace DeNA.Anjin.Loggers
/// <summary>
/// Abstract logger settings used for autopilot.
/// </summary>
public abstract class AbstractLogger : ScriptableObject, IDisposable
public abstract class AbstractLoggerAsset : ScriptableObject, IDisposable
{
#if UNITY_EDITOR
/// <summary>
Expand All @@ -21,7 +21,7 @@ public abstract class AbstractLogger : ScriptableObject, IDisposable
/// <summary>
/// Logger implementation used for autopilot.
/// </summary>
public abstract ILogger LoggerImpl { get; }
public abstract ILogger Logger { get; }

/// <inheritdoc />
public abstract void Dispose();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ namespace DeNA.Anjin.Loggers
/// A class for a logger that delegates to multiple loggers
/// </summary>
[CreateAssetMenu(fileName = "New CompositeLogger", menuName = "Anjin/Composite Logger", order = 70)]
public class CompositeLogger : AbstractLogger
public class CompositeLoggerAsset : AbstractLoggerAsset
{
/// <summary>
/// Loggers to delegates
/// </summary>
public List<AbstractLogger> loggers = new List<AbstractLogger>();
public List<AbstractLoggerAsset> loggerAssets = new List<AbstractLoggerAsset>();

private CompositeLogHandler _handler;
private Logger _logger;

/// <inheritdoc />
public override ILogger LoggerImpl
public override ILogger Logger
{
get
{
Expand All @@ -33,7 +33,7 @@ public override ILogger LoggerImpl
return _logger;
}

_handler = new CompositeLogHandler(loggers, this);
_handler = new CompositeLogHandler(loggerAssets, this);
_logger = new Logger(_handler);
return _logger;
}
Expand All @@ -47,39 +47,39 @@ public override void Dispose()

private class CompositeLogHandler : ILogHandler, IDisposable
{
private readonly List<AbstractLogger> _loggers;
private readonly AbstractLogger _owner;
private readonly List<AbstractLoggerAsset> _loggerAssets;
private readonly AbstractLoggerAsset _owner;

public CompositeLogHandler(List<AbstractLogger> loggers, AbstractLogger owner)
public CompositeLogHandler(List<AbstractLoggerAsset> loggerAssets, AbstractLoggerAsset owner)
{
_loggers = loggers;
_loggerAssets = loggerAssets;
_owner = owner;
}

/// <inheritdoc />
public void LogFormat(LogType logType, Object context, string format, params object[] args)
{
foreach (var logger in _loggers.Where(logger => logger != null && logger != _owner))
foreach (var loggerAsset in _loggerAssets.Where(x => x != null && x != _owner))
{
logger.LoggerImpl.LogFormat(logType, context, format, args);
loggerAsset.Logger.LogFormat(logType, context, format, args);
}
}

/// <inheritdoc />
public void LogException(Exception exception, Object context)
{
foreach (var logger in _loggers.Where(logger => logger != null && logger != _owner))
foreach (var loggerAsset in _loggerAssets.Where(x => x != null && x != _owner))
{
logger.LoggerImpl.LogException(exception, context);
loggerAsset.Logger.LogException(exception, context);
}
}

/// <inheritdoc />
public void Dispose()
{
foreach (var logger in _loggers.Where(logger => logger != null && logger != _owner))
foreach (var loggerAsset in _loggerAssets.Where(x => x != null && x != _owner))
{
logger.Dispose();
loggerAsset.Dispose();
}
}
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Loggers
/// Logger using <c>Debug.unityLogger</c>
/// </summary>
[CreateAssetMenu(fileName = "New ConsoleLogger", menuName = "Anjin/Console Logger", order = 71)]
public class ConsoleLogger : AbstractLogger
public class ConsoleLoggerAsset : AbstractLoggerAsset
{
/// <summary>
/// To selective enable debug log message.
Expand All @@ -20,7 +20,7 @@ public class ConsoleLogger : AbstractLogger
private ILogger _logger;

/// <inheritdoc />
public override ILogger LoggerImpl
public override ILogger Logger
{
get
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace DeNA.Anjin.Loggers
/// <see href="https://github.com/Cysharp/ZLogger"/>
/// </remarks>
[CreateAssetMenu(fileName = "New FileLogger", menuName = "Anjin/File Logger", order = 72)]
public class FileLogger : AbstractLogger
public class FileLoggerAsset : AbstractLoggerAsset
{
/// <summary>
/// Log output file path.
Expand All @@ -39,7 +39,7 @@ public class FileLogger : AbstractLogger
private ILogger _logger;

/// <inheritdoc />
public override ILogger LoggerImpl
public override ILogger Logger
{
get
{
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion Runtime/Settings/AutopilotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public class AutopilotSettings : ScriptableObject
/// <summary>
/// Logger used for this autopilot settings.
/// </summary>
public AbstractLogger logger;
public AbstractLoggerAsset loggerAsset;

/// <summary>
/// Reporter that called when some errors occurred
Expand Down
4 changes: 2 additions & 2 deletions Tests/Runtime/AutopilotTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public async Task Start_LoggerSpecified_UsingSpecifiedLogger()
var autopilotSettings = ScriptableObject.CreateInstance<AutopilotSettings>();
autopilotSettings.sceneAgentMaps = new List<SceneAgentMap>();
autopilotSettings.lifespanSec = 1;
var spyLogger = ScriptableObject.CreateInstance<SpyLogger>();
autopilotSettings.logger = spyLogger;
var spyLogger = ScriptableObject.CreateInstance<SpyLoggerAsset>();
autopilotSettings.loggerAsset = spyLogger;

await LauncherFromTest.AutopilotAsync(autopilotSettings);

Expand Down
Loading

0 comments on commit b08ff4c

Please sign in to comment.