From b08ff4c0615c839250babfc942a9ef791ca975cc Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 11 May 2024 12:20:08 +0900 Subject: [PATCH] Rename Logger to LoggerAsset, LoggerImpl to Logger --- Editor/UI/Loggers/CompositeLoggerEditor.cs | 6 +- Editor/UI/Loggers/ConsoleLoggerEditor.cs | 6 +- Editor/UI/Loggers/FileLoggerEditor.cs | 10 +- Editor/UI/Settings/AutopilotSettingsEditor.cs | 2 +- Runtime/Autopilot.cs | 14 +-- ...stractLogger.cs => AbstractLoggerAsset.cs} | 4 +- ...er.cs.meta => AbstractLoggerAsset.cs.meta} | 0 ...ositeLogger.cs => CompositeLoggerAsset.cs} | 28 +++--- ...r.cs.meta => CompositeLoggerAsset.cs.meta} | 0 ...ConsoleLogger.cs => ConsoleLoggerAsset.cs} | 4 +- ...ger.cs.meta => ConsoleLoggerAsset.cs.meta} | 0 .../{FileLogger.cs => FileLoggerAsset.cs} | 4 +- ...Logger.cs.meta => FileLoggerAsset.cs.meta} | 0 Runtime/Settings/AutopilotSettings.cs | 2 +- Tests/Runtime/AutopilotTest.cs | 4 +- ...gerTest.cs => CompositeLoggerAssetTest.cs} | 98 +++++++++---------- ....meta => CompositeLoggerAssetTest.cs.meta} | 0 ...oggerTest.cs => ConsoleLoggerAssetTest.cs} | 12 +-- ...cs.meta => ConsoleLoggerAssetTest.cs.meta} | 0 ...leLoggerTest.cs => FileLoggerAssetTest.cs} | 46 ++++----- ...st.cs.meta => FileLoggerAssetTest.cs.meta} | 0 .../{SpyLogger.cs => SpyLoggerAsset.cs} | 4 +- ...yLogger.cs.meta => SpyLoggerAsset.cs.meta} | 0 23 files changed, 120 insertions(+), 124 deletions(-) rename Runtime/Loggers/{AbstractLogger.cs => AbstractLoggerAsset.cs} (82%) rename Runtime/Loggers/{AbstractLogger.cs.meta => AbstractLoggerAsset.cs.meta} (100%) rename Runtime/Loggers/{CompositeLogger.cs => CompositeLoggerAsset.cs} (62%) rename Runtime/Loggers/{CompositeLogger.cs.meta => CompositeLoggerAsset.cs.meta} (100%) rename Runtime/Loggers/{ConsoleLogger.cs => ConsoleLoggerAsset.cs} (91%) rename Runtime/Loggers/{ConsoleLogger.cs.meta => ConsoleLoggerAsset.cs.meta} (100%) rename Runtime/Loggers/{FileLogger.cs => FileLoggerAsset.cs} (97%) rename Runtime/Loggers/{FileLogger.cs.meta => FileLoggerAsset.cs.meta} (100%) rename Tests/Runtime/Loggers/{CompositeLoggerTest.cs => CompositeLoggerAssetTest.cs} (74%) rename Tests/Runtime/Loggers/{CompositeLoggerTest.cs.meta => CompositeLoggerAssetTest.cs.meta} (100%) rename Tests/Runtime/Loggers/{ConsoleLoggerTest.cs => ConsoleLoggerAssetTest.cs} (82%) rename Tests/Runtime/Loggers/{ConsoleLoggerTest.cs.meta => ConsoleLoggerAssetTest.cs.meta} (100%) rename Tests/Runtime/Loggers/{FileLoggerTest.cs => FileLoggerAssetTest.cs} (88%) rename Tests/Runtime/Loggers/{FileLoggerTest.cs.meta => FileLoggerAssetTest.cs.meta} (100%) rename Tests/Runtime/TestDoubles/{SpyLogger.cs => SpyLoggerAsset.cs} (93%) rename Tests/Runtime/TestDoubles/{SpyLogger.cs.meta => SpyLoggerAsset.cs.meta} (100%) diff --git a/Editor/UI/Loggers/CompositeLoggerEditor.cs b/Editor/UI/Loggers/CompositeLoggerEditor.cs index 0b39e4a..3550ec9 100644 --- a/Editor/UI/Loggers/CompositeLoggerEditor.cs +++ b/Editor/UI/Loggers/CompositeLoggerEditor.cs @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers /// /// Editor GUI for CompositeLogger. /// - [CustomEditor(typeof(CompositeLogger))] + [CustomEditor(typeof(CompositeLoggerAsset))] public class CompositeLoggerEditor : UnityEditor.Editor { private static readonly string s_description = L10n.Tr("Description"); @@ -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(); diff --git a/Editor/UI/Loggers/ConsoleLoggerEditor.cs b/Editor/UI/Loggers/ConsoleLoggerEditor.cs index 640b2e8..64a63bf 100644 --- a/Editor/UI/Loggers/ConsoleLoggerEditor.cs +++ b/Editor/UI/Loggers/ConsoleLoggerEditor.cs @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers /// /// Editor GUI for ConsoleLogger. /// - [CustomEditor(typeof(ConsoleLogger))] + [CustomEditor(typeof(ConsoleLoggerAsset))] public class ConsoleLoggerEditor : UnityEditor.Editor { private static readonly string s_description = L10n.Tr("Description"); @@ -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(); diff --git a/Editor/UI/Loggers/FileLoggerEditor.cs b/Editor/UI/Loggers/FileLoggerEditor.cs index 1ddb792..53ff52c 100644 --- a/Editor/UI/Loggers/FileLoggerEditor.cs +++ b/Editor/UI/Loggers/FileLoggerEditor.cs @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Editor.UI.Loggers /// /// Editor GUI for FileLogger. /// - [CustomEditor(typeof(FileLogger))] + [CustomEditor(typeof(FileLoggerAsset))] public class FileLoggerEditor : UnityEditor.Editor { private static readonly string s_description = L10n.Tr("Description"); @@ -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(); diff --git a/Editor/UI/Settings/AutopilotSettingsEditor.cs b/Editor/UI/Settings/AutopilotSettingsEditor.cs index fab612d..2596290 100644 --- a/Editor/UI/Settings/AutopilotSettingsEditor.cs +++ b/Editor/UI/Settings/AutopilotSettingsEditor.cs @@ -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)); diff --git a/Runtime/Autopilot.cs b/Runtime/Autopilot.cs index 6a656c7..8251569 100644 --- a/Runtime/Autopilot.cs +++ b/Runtime/Autopilot.cs @@ -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; @@ -18,6 +19,7 @@ namespace DeNA.Anjin /// public class Autopilot : MonoBehaviour { + private AbstractLoggerAsset _loggerAsset; private ILogger _logger; private RandomFactory _randomFactory; private IAgentDispatcher _dispatcher; @@ -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)) { @@ -99,7 +95,7 @@ private void OnDestroy() _dispatcher?.Dispose(); _logMessageHandler?.Dispose(); - _settings.logger?.Dispose(); + _settings.loggerAsset?.Dispose(); } /// diff --git a/Runtime/Loggers/AbstractLogger.cs b/Runtime/Loggers/AbstractLoggerAsset.cs similarity index 82% rename from Runtime/Loggers/AbstractLogger.cs rename to Runtime/Loggers/AbstractLoggerAsset.cs index 11bbc81..820c7e3 100644 --- a/Runtime/Loggers/AbstractLogger.cs +++ b/Runtime/Loggers/AbstractLoggerAsset.cs @@ -9,7 +9,7 @@ namespace DeNA.Anjin.Loggers /// /// Abstract logger settings used for autopilot. /// - public abstract class AbstractLogger : ScriptableObject, IDisposable + public abstract class AbstractLoggerAsset : ScriptableObject, IDisposable { #if UNITY_EDITOR /// @@ -21,7 +21,7 @@ public abstract class AbstractLogger : ScriptableObject, IDisposable /// /// Logger implementation used for autopilot. /// - public abstract ILogger LoggerImpl { get; } + public abstract ILogger Logger { get; } /// public abstract void Dispose(); diff --git a/Runtime/Loggers/AbstractLogger.cs.meta b/Runtime/Loggers/AbstractLoggerAsset.cs.meta similarity index 100% rename from Runtime/Loggers/AbstractLogger.cs.meta rename to Runtime/Loggers/AbstractLoggerAsset.cs.meta diff --git a/Runtime/Loggers/CompositeLogger.cs b/Runtime/Loggers/CompositeLoggerAsset.cs similarity index 62% rename from Runtime/Loggers/CompositeLogger.cs rename to Runtime/Loggers/CompositeLoggerAsset.cs index db7983b..21bffdb 100644 --- a/Runtime/Loggers/CompositeLogger.cs +++ b/Runtime/Loggers/CompositeLoggerAsset.cs @@ -13,18 +13,18 @@ namespace DeNA.Anjin.Loggers /// A class for a logger that delegates to multiple loggers /// [CreateAssetMenu(fileName = "New CompositeLogger", menuName = "Anjin/Composite Logger", order = 70)] - public class CompositeLogger : AbstractLogger + public class CompositeLoggerAsset : AbstractLoggerAsset { /// /// Loggers to delegates /// - public List loggers = new List(); + public List loggerAssets = new List(); private CompositeLogHandler _handler; private Logger _logger; /// - public override ILogger LoggerImpl + public override ILogger Logger { get { @@ -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; } @@ -47,39 +47,39 @@ public override void Dispose() private class CompositeLogHandler : ILogHandler, IDisposable { - private readonly List _loggers; - private readonly AbstractLogger _owner; + private readonly List _loggerAssets; + private readonly AbstractLoggerAsset _owner; - public CompositeLogHandler(List loggers, AbstractLogger owner) + public CompositeLogHandler(List loggerAssets, AbstractLoggerAsset owner) { - _loggers = loggers; + _loggerAssets = loggerAssets; _owner = owner; } /// 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); } } /// 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); } } /// 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(); } } } diff --git a/Runtime/Loggers/CompositeLogger.cs.meta b/Runtime/Loggers/CompositeLoggerAsset.cs.meta similarity index 100% rename from Runtime/Loggers/CompositeLogger.cs.meta rename to Runtime/Loggers/CompositeLoggerAsset.cs.meta diff --git a/Runtime/Loggers/ConsoleLogger.cs b/Runtime/Loggers/ConsoleLoggerAsset.cs similarity index 91% rename from Runtime/Loggers/ConsoleLogger.cs rename to Runtime/Loggers/ConsoleLoggerAsset.cs index ea18d8c..4d61dfc 100644 --- a/Runtime/Loggers/ConsoleLogger.cs +++ b/Runtime/Loggers/ConsoleLoggerAsset.cs @@ -10,7 +10,7 @@ namespace DeNA.Anjin.Loggers /// Logger using Debug.unityLogger /// [CreateAssetMenu(fileName = "New ConsoleLogger", menuName = "Anjin/Console Logger", order = 71)] - public class ConsoleLogger : AbstractLogger + public class ConsoleLoggerAsset : AbstractLoggerAsset { /// /// To selective enable debug log message. @@ -20,7 +20,7 @@ public class ConsoleLogger : AbstractLogger private ILogger _logger; /// - public override ILogger LoggerImpl + public override ILogger Logger { get { diff --git a/Runtime/Loggers/ConsoleLogger.cs.meta b/Runtime/Loggers/ConsoleLoggerAsset.cs.meta similarity index 100% rename from Runtime/Loggers/ConsoleLogger.cs.meta rename to Runtime/Loggers/ConsoleLoggerAsset.cs.meta diff --git a/Runtime/Loggers/FileLogger.cs b/Runtime/Loggers/FileLoggerAsset.cs similarity index 97% rename from Runtime/Loggers/FileLogger.cs rename to Runtime/Loggers/FileLoggerAsset.cs index be6d8b4..9cbc3a8 100644 --- a/Runtime/Loggers/FileLogger.cs +++ b/Runtime/Loggers/FileLoggerAsset.cs @@ -17,7 +17,7 @@ namespace DeNA.Anjin.Loggers /// /// [CreateAssetMenu(fileName = "New FileLogger", menuName = "Anjin/File Logger", order = 72)] - public class FileLogger : AbstractLogger + public class FileLoggerAsset : AbstractLoggerAsset { /// /// Log output file path. @@ -39,7 +39,7 @@ public class FileLogger : AbstractLogger private ILogger _logger; /// - public override ILogger LoggerImpl + public override ILogger Logger { get { diff --git a/Runtime/Loggers/FileLogger.cs.meta b/Runtime/Loggers/FileLoggerAsset.cs.meta similarity index 100% rename from Runtime/Loggers/FileLogger.cs.meta rename to Runtime/Loggers/FileLoggerAsset.cs.meta diff --git a/Runtime/Settings/AutopilotSettings.cs b/Runtime/Settings/AutopilotSettings.cs index df6a754..9d58170 100644 --- a/Runtime/Settings/AutopilotSettings.cs +++ b/Runtime/Settings/AutopilotSettings.cs @@ -129,7 +129,7 @@ public class AutopilotSettings : ScriptableObject /// /// Logger used for this autopilot settings. /// - public AbstractLogger logger; + public AbstractLoggerAsset loggerAsset; /// /// Reporter that called when some errors occurred diff --git a/Tests/Runtime/AutopilotTest.cs b/Tests/Runtime/AutopilotTest.cs index f13684f..cd87fa0 100644 --- a/Tests/Runtime/AutopilotTest.cs +++ b/Tests/Runtime/AutopilotTest.cs @@ -32,8 +32,8 @@ public async Task Start_LoggerSpecified_UsingSpecifiedLogger() var autopilotSettings = ScriptableObject.CreateInstance(); autopilotSettings.sceneAgentMaps = new List(); autopilotSettings.lifespanSec = 1; - var spyLogger = ScriptableObject.CreateInstance(); - autopilotSettings.logger = spyLogger; + var spyLogger = ScriptableObject.CreateInstance(); + autopilotSettings.loggerAsset = spyLogger; await LauncherFromTest.AutopilotAsync(autopilotSettings); diff --git a/Tests/Runtime/Loggers/CompositeLoggerTest.cs b/Tests/Runtime/Loggers/CompositeLoggerAssetTest.cs similarity index 74% rename from Tests/Runtime/Loggers/CompositeLoggerTest.cs rename to Tests/Runtime/Loggers/CompositeLoggerAssetTest.cs index 7f2dbe9..72d217e 100644 --- a/Tests/Runtime/Loggers/CompositeLoggerTest.cs +++ b/Tests/Runtime/Loggers/CompositeLoggerAssetTest.cs @@ -9,7 +9,7 @@ namespace DeNA.Anjin.Loggers { [TestFixture] - public class CompositeLoggerTest + public class CompositeLoggerAssetTest { private static Exception CreateExceptionWithStacktrace(string message) { @@ -26,14 +26,14 @@ private static Exception CreateExceptionWithStacktrace(string message) [Test] public void LogFormat_CompositeMultipleLoggers_OutputBothLoggers() { - var logger1 = ScriptableObject.CreateInstance(); - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(logger1); - sut.loggers.Add(logger2); + var logger1 = ScriptableObject.CreateInstance(); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(logger1); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); Assert.That(logger1.Logs, Does.Contain(message)); Assert.That(logger2.Logs, Does.Contain(message)); @@ -42,13 +42,13 @@ public void LogFormat_CompositeMultipleLoggers_OutputBothLoggers() [Test] public void LogFormat_LoggersIncludesNull_IgnoreNull() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(null); - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(null); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); Assert.That(logger2.Logs, Does.Contain(message)); } @@ -56,13 +56,13 @@ public void LogFormat_LoggersIncludesNull_IgnoreNull() [Test] public void LogFormat_NestingLogger_IgnoreNested() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(sut); // nesting - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(sut); // nesting + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); Assert.That(logger2.Logs, Does.Contain(message)); } @@ -70,15 +70,15 @@ public void LogFormat_NestingLogger_IgnoreNested() [Test] public void LogException_CompositeMultipleLoggers_OutputBothLoggers() { - var logger1 = ScriptableObject.CreateInstance(); - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(logger1); - sut.loggers.Add(logger2); + var logger1 = ScriptableObject.CreateInstance(); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(logger1); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); Assert.That(logger1.Logs, Does.Contain(exception.ToString())); Assert.That(logger2.Logs, Does.Contain(exception.ToString())); @@ -87,14 +87,14 @@ public void LogException_CompositeMultipleLoggers_OutputBothLoggers() [Test] public void LogException_LoggersIncludesNull_IgnoreNull() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(null); - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(null); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); Assert.That(logger2.Logs, Does.Contain(exception.ToString())); } @@ -102,14 +102,14 @@ public void LogException_LoggersIncludesNull_IgnoreNull() [Test] public void LogException_NestingLogger_IgnoreNested() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(sut); // nesting - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(sut); // nesting + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); Assert.That(logger2.Logs, Does.Contain(exception.ToString())); } @@ -117,14 +117,14 @@ public void LogException_NestingLogger_IgnoreNested() [Test] public void Dispose_CompositeMultipleLoggers_DisposeAllLoggers() { - var logger1 = ScriptableObject.CreateInstance(); - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(logger1); - sut.loggers.Add(logger2); + var logger1 = ScriptableObject.CreateInstance(); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(logger1); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); sut.Dispose(); Assert.That(logger1.Disposed, Is.True); @@ -134,13 +134,13 @@ public void Dispose_CompositeMultipleLoggers_DisposeAllLoggers() [Test] public void Dispose_LoggersIncludesNull_IgnoreNull() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(null); - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(null); + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); sut.Dispose(); Assert.That(logger2.Disposed, Is.True); @@ -149,13 +149,13 @@ public void Dispose_LoggersIncludesNull_IgnoreNull() [Test] public void Dispose_NestingLogger_IgnoreNested() { - var logger2 = ScriptableObject.CreateInstance(); - var sut = ScriptableObject.CreateInstance(); - sut.loggers.Add(sut); // nesting - sut.loggers.Add(logger2); + var logger2 = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); + sut.loggerAssets.Add(sut); // nesting + sut.loggerAssets.Add(logger2); var message = TestContext.CurrentContext.Test.Name; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); sut.Dispose(); Assert.That(logger2.Disposed, Is.True); diff --git a/Tests/Runtime/Loggers/CompositeLoggerTest.cs.meta b/Tests/Runtime/Loggers/CompositeLoggerAssetTest.cs.meta similarity index 100% rename from Tests/Runtime/Loggers/CompositeLoggerTest.cs.meta rename to Tests/Runtime/Loggers/CompositeLoggerAssetTest.cs.meta diff --git a/Tests/Runtime/Loggers/ConsoleLoggerTest.cs b/Tests/Runtime/Loggers/ConsoleLoggerAssetTest.cs similarity index 82% rename from Tests/Runtime/Loggers/ConsoleLoggerTest.cs rename to Tests/Runtime/Loggers/ConsoleLoggerAssetTest.cs index b448425..f29687b 100644 --- a/Tests/Runtime/Loggers/ConsoleLoggerTest.cs +++ b/Tests/Runtime/Loggers/ConsoleLoggerAssetTest.cs @@ -8,15 +8,15 @@ namespace DeNA.Anjin.Loggers { [TestFixture] - public class ConsoleLoggerTest + public class ConsoleLoggerAssetTest { [Test] public void FilterLogTypeIsNotSet_LogAsDefault() { var message = TestContext.CurrentContext.Test.Name; - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); LogAssert.Expect(LogType.Log, message); LogAssert.NoUnexpectedReceived(); @@ -28,11 +28,11 @@ public void FilterLogTypeSpecified( LogType logType) { var message = TestContext.CurrentContext.Test.Name; - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.filterLogType = logType; - sut.LoggerImpl.Log(logType, message); - sut.LoggerImpl.Log("Not output message because LogType.Log"); + sut.Logger.Log(logType, message); + sut.Logger.Log("Not output message because LogType.Log"); LogAssert.Expect(logType, message); LogAssert.NoUnexpectedReceived(); diff --git a/Tests/Runtime/Loggers/ConsoleLoggerTest.cs.meta b/Tests/Runtime/Loggers/ConsoleLoggerAssetTest.cs.meta similarity index 100% rename from Tests/Runtime/Loggers/ConsoleLoggerTest.cs.meta rename to Tests/Runtime/Loggers/ConsoleLoggerAssetTest.cs.meta diff --git a/Tests/Runtime/Loggers/FileLoggerTest.cs b/Tests/Runtime/Loggers/FileLoggerAssetTest.cs similarity index 88% rename from Tests/Runtime/Loggers/FileLoggerTest.cs rename to Tests/Runtime/Loggers/FileLoggerAssetTest.cs index be6cccb..9f44b0e 100644 --- a/Tests/Runtime/Loggers/FileLoggerTest.cs +++ b/Tests/Runtime/Loggers/FileLoggerAssetTest.cs @@ -13,7 +13,7 @@ namespace DeNA.Anjin.Loggers { [TestFixture] - public class FileLoggerTest + public class FileLoggerAssetTest { private const string LogsDirectoryPath = "Logs/FileLoggerTest"; private const string TimestampRegex = @"\[\d{2}:\d{2}:\d{2}\.\d{3}\] "; @@ -45,11 +45,11 @@ public async Task GetLoggerImpl_DirectoryDoesNotExist_CreateDirectoryAndWriteToF var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); sut.Dispose(); await Task.Yield(); @@ -64,11 +64,11 @@ public async Task GetLoggerImpl_FileExists_OverwrittenToFile() var path = GetOutputPath(); File.WriteAllText(path, "Existing content"); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); sut.Dispose(); await Task.Yield(); @@ -81,12 +81,12 @@ public async Task LogFormat_WriteToFile() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; - sut.LoggerImpl.Log(message); - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); + sut.Logger.Log(message); sut.Dispose(); await Task.Yield(); @@ -99,16 +99,16 @@ public async Task LogFormat_Disposed_NotWriteToFile() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; - sut.LoggerImpl.Log(message); - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); + sut.Logger.Log(message); sut.Dispose(); await Task.Yield(); - sut.LoggerImpl.Log(message); // write after disposed + sut.Logger.Log(message); // write after disposed await Task.Yield(); var actual = File.ReadAllText(path); @@ -120,14 +120,14 @@ public async Task LogFormat_WithTimestamp_WriteTimestamp() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = true; - sut.LoggerImpl.Log(message); + sut.Logger.Log(message); await UniTask.NextFrame(); - sut.LoggerImpl.Log(message); - sut.LoggerImpl.Log(message); // using cache + sut.Logger.Log(message); + sut.Logger.Log(message); // using cache sut.Dispose(); await Task.Yield(); @@ -145,12 +145,12 @@ public async Task LogException_WriteToFile() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); sut.Dispose(); await Task.Yield(); @@ -163,16 +163,16 @@ public async Task LogException_Disposed_NotWriteToFile() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = false; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); sut.Dispose(); await Task.Yield(); - sut.LoggerImpl.LogException(exception); // write after disposed + sut.Logger.LogException(exception); // write after disposed await Task.Yield(); var actual = File.ReadAllText(path); @@ -184,12 +184,12 @@ public async Task LogException_WithTimestamp_WriteTimestamp() { var message = TestContext.CurrentContext.Test.Name; var path = GetOutputPath(); - var sut = ScriptableObject.CreateInstance(); + var sut = ScriptableObject.CreateInstance(); sut.outputPath = path; sut.timestamp = true; var exception = CreateExceptionWithStacktrace(message); - sut.LoggerImpl.LogException(exception); + sut.Logger.LogException(exception); sut.Dispose(); await Task.Yield(); diff --git a/Tests/Runtime/Loggers/FileLoggerTest.cs.meta b/Tests/Runtime/Loggers/FileLoggerAssetTest.cs.meta similarity index 100% rename from Tests/Runtime/Loggers/FileLoggerTest.cs.meta rename to Tests/Runtime/Loggers/FileLoggerAssetTest.cs.meta diff --git a/Tests/Runtime/TestDoubles/SpyLogger.cs b/Tests/Runtime/TestDoubles/SpyLoggerAsset.cs similarity index 93% rename from Tests/Runtime/TestDoubles/SpyLogger.cs rename to Tests/Runtime/TestDoubles/SpyLoggerAsset.cs index c541c29..6689345 100644 --- a/Tests/Runtime/TestDoubles/SpyLogger.cs +++ b/Tests/Runtime/TestDoubles/SpyLoggerAsset.cs @@ -9,14 +9,14 @@ namespace DeNA.Anjin.TestDoubles { - public class SpyLogger : AbstractLogger + public class SpyLoggerAsset : AbstractLoggerAsset { public bool Disposed { get; private set; } private SpyLogHandler _handler; private ILogger _logger; - public override ILogger LoggerImpl + public override ILogger Logger { get { diff --git a/Tests/Runtime/TestDoubles/SpyLogger.cs.meta b/Tests/Runtime/TestDoubles/SpyLoggerAsset.cs.meta similarity index 100% rename from Tests/Runtime/TestDoubles/SpyLogger.cs.meta rename to Tests/Runtime/TestDoubles/SpyLoggerAsset.cs.meta