Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Loggers and Reporters support #92

Merged
merged 8 commits into from
Nov 1, 2024
18 changes: 9 additions & 9 deletions Editor/Localization/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ msgid "JUnit report output path"
msgstr "JUnit形式のレポートファイル出力パス(省略時は出力されない)"

# logger
msgid "Logger"
msgstr "Logger"
msgid "Loggers"
msgstr "Loggers"

# logger tooltip
msgid "Logger used for this autopilot settings. If omitted, Debug.unityLogger will be used as default."
msgstr "オートパイロットが使用するLogger指定します。省略時は Debug.unityLogger がデフォルトとして使用されます"
msgid "List of Loggers used for this autopilot settings. If omitted, Debug.unityLogger will be used as default."
msgstr "オートパイロットで使用するLoggerを指定します。省略時は Debug.unityLogger がデフォルトとして使用されます"

# reporter
msgid "Reporter"
msgstr "Reporter"
msgid "Reporters"
msgstr "Reporters"

# reporter tooltip
msgid "Reporter that called when some errors occurred in target application"
msgstr "対象のアプリケーションで発生したエラーを通知するReporterを指定します"
msgid "List of Reporters to be called on Autopilot terminate."
msgstr "オートパイロット終了時に通知を行なうReporterを指定します"

# Header: Error Handling Settings
msgid "Error Handling Settings"
Expand Down Expand Up @@ -460,7 +460,7 @@ msgstr "このReporterインスタンスの説明"

#: Editor/UI/Reporters/CompositeReporterEditor.cs
msgid "Reporters"
msgstr "Reporter"
msgstr "Reporters"


#: Editor/UI/Reporters/SlackReporterEditor.cs
Expand Down
23 changes: 12 additions & 11 deletions Editor/UI/Settings/AutopilotSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,17 @@ public class AutopilotSettingsEditor : UnityEditor.Editor
private static readonly string s_junitReportPath = L10n.Tr("JUnit Report Path");
private static readonly string s_junitReportPathTooltip = L10n.Tr("JUnit report output path");

private static readonly string s_logger = L10n.Tr("Logger");
private static readonly string s_loggers = L10n.Tr("Loggers");

private static readonly string s_loggerTooltip =
L10n.Tr("Logger used for this autopilot settings. If omitted, Debug.unityLogger will be used as default.");
private static readonly string s_loggersTooltip =
L10n.Tr(
"List of Loggers used for this autopilot settings. If omitted, Debug.unityLogger will be used as default.");

private static readonly string s_reporter = L10n.Tr("Reporter");
private static readonly string s_reporters = L10n.Tr("Reporters");

private static readonly string s_reportersTooltip =
L10n.Tr("List of Reporters to be called on Autopilot terminate.");

private static readonly string s_reporterTooltip =
L10n.Tr("Reporter that called when some errors occurred in target application");

private static readonly string s_errorHandlingSettingsHeader = L10n.Tr("Error Handling Settings");
private static readonly string s_handleException = L10n.Tr("Handle Exception");
private static readonly string s_handleExceptionTooltip = L10n.Tr("Notify when Exception detected in log");
Expand Down Expand Up @@ -95,10 +96,10 @@ 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.loggerAsset)),
new GUIContent(s_logger, s_loggerTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporter)),
new GUIContent(s_reporter, s_reporterTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.loggerAssets)),
new GUIContent(s_loggers, s_loggersTooltip));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.reporters)),
new GUIContent(s_reporters, s_reportersTooltip));

DrawHeader(s_errorHandlingSettingsHeader);
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(AutopilotSettings.handleException)),
Expand Down
2 changes: 1 addition & 1 deletion Editor/UI/Settings/AutopilotStateEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void OnInspectorGUI()
{
var state = AutopilotState.Instance;

EditorGUI.BeginDisabledGroup(state.IsRunning || EditorApplication.isPlayingOrWillChangePlaymode);
EditorGUI.BeginDisabledGroup(!state.IsRunning || EditorApplication.isPlayingOrWillChangePlaymode);
if (GUILayout.Button(s_resetButton))
{
state.Reset();
Expand Down
32 changes: 5 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ This item can also be overridden from the commandline (see below).
<dt>Random Seed</dt><dd>Specify when you want to fix the seed given to the pseudo-random number generator (optional). This is a setting related to the pseudo-random number generator used by the autopilot. To fix the seed of the pseudo-random number generator in the game itself, it is necessary to implement this setting on the game title side. </dd>
<dt>Time Scale</dt><dd>Time.timeScale. Default is 1.0</dd>
<dt>JUnit Report Path</dt><dd>Specifies the JUnit format report file output path (optional). If there are zero errors and zero failures, the autopilot run is considered to have completed successfully. </dd>
<dt>Logger</dt><dd>Logger used for this autopilot settings. If omitted, <code>Debug.unityLogger</code> will be used as default.</dd>
<dt>Reporter</dt><dd>Reporter to be called on Autopilot terminate.</dd>
<dt>Loggers</dt><dd>Logger used for this autopilot settings. If omitted, <code>Debug.unityLogger</code> will be used as default.</dd>
<dt>Reporters</dt><dd>Reporter to be called on Autopilot terminate.</dd>
</dl>

#### Error Handling Settings
Expand Down Expand Up @@ -394,17 +394,6 @@ This can be accomplished with `ParallelCompositeAgent`, but it is easier to set
The following Logger types are provided. These can be used as they are, or game-title-specific custom Loggers can be implemented and used.


### CompositeLogger

A Logger that delegates to multiple Loggers.

The instance of this Logger (.asset file) can have the following settings.

<dl>
<dt>Loggers</dt><dd>A list of Logger to delegates</dd>
</dl>


### ConsoleLogger

A Logger that outputs to a console.
Expand Down Expand Up @@ -436,17 +425,6 @@ The instance of this Logger (.asset file) can have the following settings.
The following Reporter types are provided. These can be used as they are, or game-title-specific custom Reporters can be implemented and used.


### CompositeReporter

A Reporter that delegates to multiple Reporters.

The instance of this Reporter (.asset file) can have the following settings.

<dl>
<dt>Reporters</dt><dd>A list of Reporter to delegates</dd>
</dl>


### SlackReporter

A Reporter that post report to Slack.
Expand Down Expand Up @@ -501,7 +479,7 @@ Note that it is convenient to set the `[CreateAssetMenu]` attribute to create an
### Custom Loggers

A custom Logger is created by inheriting from `Anjin.Logers.AbstractLoggerAsset`.
Simply implement the `ILogger Logger { get; }` property.
You must implement the `Logger { get; }` property to return custom `UnityEngine.ILogger` implementation.

Note that it is convenient to set the `[CreateAssetMenu]` attribute to create an instance from the context menu.

Expand Down Expand Up @@ -679,12 +657,12 @@ Find out why you have an old UniTask installed.
e.g., Check the contents of Packages/packages-lock.json generated by the Unity editor; use your IDE's code definition jump function to check where the source file of `UniTask.WaitForEndOfFrame()` is.


### Warning message "settings has been obsoleted" when running autopilot
### Warning message "settings has been obsolete" when running autopilot

For example, the following warning message may be output log.

```
Slack settings in AutopilotSettings has been obsoleted.
Slack settings in AutopilotSettings has been obsolete.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
```

Expand Down
32 changes: 5 additions & 27 deletions README_ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ v1.0.0時点では `EmergencyExitAgent` の使用を想定しています。
<dt>Random Seed</dt><dd>疑似乱数発生器に与えるシードを固定したいときに指定します(省略可)。なお、これはオートパイロットの使用する疑似乱数発生器に関する設定であり、ゲーム本体の疑似乱数発生器シードを固定するにはゲームタイトル側での実装が必要です。</dd>
<dt>Time Scale</dt><dd>Time.timeScaleを指定します。デフォルトは1.0</dd>
<dt>JUnit Report Path</dt><dd>JUnit形式のレポートファイル出力パスを指定します(省略可)。オートパイロット実行の成否は、Unityエディターの終了コードでなくこのファイルを見て判断するのが確実です。errors, failuresともに0件であれば正常終了と判断できます。</dd>
<dt>Logger</dt><dd>オートパイロットが使用するLogger指定します。省略時は <code>Debug.unityLogger</code> がデフォルトとして使用されます</dd>
<dt>Reporter</dt><dd>オートパイロット終了時に通知を行なうReporterを指定します</dd>
<dt>Loggers</dt><dd>オートパイロットが使用するLogger指定します。省略時は <code>Debug.unityLogger</code> がデフォルトとして使用されます</dd>
<dt>Reporters</dt><dd>オートパイロット終了時に通知を行なうReporterを指定します</dd>
</dl>

#### エラーハンドリング設定
Expand Down Expand Up @@ -398,17 +398,6 @@ SerialCompositeAgentと組み合わせることで、一連の操作を何周も
以下のLoggerタイプが用意されています。これらをそのまま使用することも、ゲームタイトル固有のカスタムLoggerを実装して使用することも可能です。


### CompositeLogger

複数のLoggerを登録し、そのすべてにログ出力を委譲するLoggerです。

このLoggerのインスタンス(.assetファイル)には以下を設定できます。

<dl>
<dt>Loggers</dt><dd>ログ出力を委譲するLoggerのリスト</dd>
</dl>


### ConsoleLogger

ログをコンソールに出力するLoggerです。
Expand Down Expand Up @@ -440,17 +429,6 @@ SerialCompositeAgentと組み合わせることで、一連の操作を何周も
以下のReporterタイプが用意されています。これらをそのまま使用することも、ゲームタイトル固有のカスタムReporterを実装して使用することも可能です。


### CompositeReporter

複数のReporterを登録し、そのすべてにレポート送信を委譲するReporterです。

このReporterのインスタンス(.assetファイル)には以下を設定できます。

<dl>
<dt>Reporters</dt><dd>レポート送信を委譲するReporterのリスト</dd>
</dl>


### SlackReporter

Slackにレポート送信するReporterです。
Expand Down Expand Up @@ -506,7 +484,7 @@ Assembly Definition File (asmdef) のAuto Referencedをoff、Define Constraints
### カスタムLogger

カスタムLoggerは、`Anjin.Logers.AbstractLoggerAsset` を継承して作ります。
`ILogger Logger { get; }` プロパティを実装するだけです
`UnityEngine.ILogger` の実装を返すプロパティ `Logger { get; }` を実装する必要があります

なお、`[CreateAssetMenu]`アトリビュートを設定しておくとコンテキストメニューからインスタンス生成ができて便利です。

Expand Down Expand Up @@ -688,12 +666,12 @@ Compiler Error at Library\PackageCache\[email protected]\Runtime\Reporters\Sl
Unityエディターが生成するPackages/packages-lock.jsonの中身を確認するか、お使いのIDEのコード定義ジャンプ機能で `UniTask.WaitForEndOfFrame()` のソースファイルがどこにあるかを確認するなどして、古いUniTaskがインストールされている原因を突き止められます。


### 実行中に "settings has been obsoleted" 警告が出る
### 実行中に "settings has been obsolete" 警告が出る

たとえば次のような警告メッセージが出力されることがあります。

```
Slack settings in AutopilotSettings has been obsoleted.
Slack settings in AutopilotSettings has been obsolete.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace DeNA.Anjin.Attributes
public class InitializeOnLaunchAutopilotAttribute : PreserveAttribute
{
internal const int InitializeLoggerOrder = -20000;
internal const int CovertObsoleteOrder = -10000;
internal const int InitializeSettings = -10000;
internal const int DefaultOrder = 0;

/// <summary>
Expand Down
43 changes: 3 additions & 40 deletions Runtime/Autopilot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections;
using System.Threading;
using Cysharp.Threading.Tasks;
using DeNA.Anjin.Loggers;
using DeNA.Anjin.Reporters;
using DeNA.Anjin.Settings;
using DeNA.Anjin.Utilities;
using UnityEngine;
Expand Down Expand Up @@ -38,7 +36,6 @@ UniTask TerminateAsync(ExitCode exitCode, string message = null, string stackTra
/// </summary>
public class Autopilot : MonoBehaviour, ITerminatable
{
private AbstractLoggerAsset _loggerAsset;
private ILogger _logger;
private RandomFactory _randomFactory;
private IAgentDispatcher _dispatcher;
Expand All @@ -54,10 +51,8 @@ private void Start()
_settings = _state.settings;
Assert.IsNotNull(_settings);

_loggerAsset = _settings.loggerAsset;
_logger = _loggerAsset != null ? _loggerAsset.Logger : CreateDefaultLogger();

ConvertSlackReporterFromObsoleteSlackSettings(_settings, _logger);
_logger = _settings.LoggerAsset.Logger;
// Note: Set a default logger if no logger settings. see: AutopilotSettings.Initialize method.

if (!int.TryParse(_settings.randomSeed, out var seed))
{
Expand Down Expand Up @@ -105,38 +100,6 @@ private void DispatchByLoadedScenes()
}
}

/// <summary>
/// Returns an logger that autopilot uses. You can change a logger by overriding this method.
/// Default logger is that write to console.
/// </summary>
/// <returns>A new logger that write to console</returns>
private static ILogger CreateDefaultLogger()
{
return Debug.unityLogger;
}

[Obsolete("Remove this method when bump major version")]
internal static void ConvertSlackReporterFromObsoleteSlackSettings(AutopilotSettings settings, ILogger logger)
{
if (string.IsNullOrEmpty(settings.slackToken) || string.IsNullOrEmpty(settings.slackChannels) ||
settings.reporter != null)
// TODO: This condition will change when the AutopilotSettings.reporter is changed to a List<AbstractReporter>.
{
return;
}

logger.Log(LogType.Warning, @"Slack settings in AutopilotSettings has been obsoleted.
Please delete the value using Debug Mode in the Inspector window. And create a SlackReporter asset file.
This time, temporarily generate and use SlackReporter instance.");

var reporter = ScriptableObject.CreateInstance<SlackReporter>();
reporter.slackToken = settings.slackToken;
reporter.slackChannels = settings.slackChannels;
reporter.mentionSubTeamIDs = settings.mentionSubTeamIDs;
reporter.addHereInSlackMessage = settings.addHereInSlackMessage;
settings.reporter = reporter;
}

/// <summary>
/// Terminate when ran specified time.
/// </summary>
Expand All @@ -157,7 +120,7 @@ private void OnDestroy()
_logger?.Log("Destroy Autopilot object");
_dispatcher?.Dispose();
_logMessageHandler?.Dispose();
_settings.loggerAsset?.Dispose();
_settings.LoggerAsset?.Dispose();
}

/// <inheritdoc/>
Expand Down
6 changes: 3 additions & 3 deletions Runtime/Loggers/CompositeLoggerAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
namespace DeNA.Anjin.Loggers
{
/// <summary>
/// A class for a logger that delegates to multiple loggers
/// A class for a logger that delegates to multiple loggers.
/// This class is for Internal use. However, It is public for historical reasons.
/// </summary>
[CreateAssetMenu(fileName = "New CompositeLogger", menuName = "Anjin/Composite Logger", order = 70)]
public class CompositeLoggerAsset : AbstractLoggerAsset
{
/// <summary>
/// Loggers to delegates
/// Loggers to delegate.
/// </summary>
public List<AbstractLoggerAsset> loggerAssets = new List<AbstractLoggerAsset>();

Expand Down
7 changes: 3 additions & 4 deletions Runtime/Reporters/CompositeReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
namespace DeNA.Anjin.Reporters
{
/// <summary>
/// A class for reporters that delegate to multiple reporters
/// A class for reporters that delegate to multiple reporters.
/// This class is for Internal use. However, It is public for historical reasons.
/// </summary>
[CreateAssetMenu(fileName = "New CompositeReporter", menuName = "Anjin/Composite Reporter", order = 51)]
public class CompositeReporter : AbstractReporter
{
/// <summary>
/// Reporters to delegate
/// Reporters to delegate.
/// </summary>
public List<AbstractReporter> reporters = new List<AbstractReporter>();


/// <inheritdoc />
public override async UniTask PostReportAsync(
string message,
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Reporters/SlackReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace DeNA.Anjin.Reporters
/// <summary>
/// Post report to Slack
/// </summary>
[CreateAssetMenu(fileName = "New SlackReporter", menuName = "Anjin/Slack Reporter", order = 50)]
[CreateAssetMenu(fileName = "New SlackReporter", menuName = "Anjin/Slack Reporter", order = 90)]
public class SlackReporter : AbstractReporter
{
/// <summary>
Expand Down
Loading