Debug.Log()
でイイじゃんね。て感じもありますが、最初にこれさえやっておけば後から最低限の対応ができるテンプレート。
- Unity コンソールのログをダブルクリックしたときにロガーの
.cs
ファイルが開いたりしない。ちゃんとログを出力したスクリプトが開く。 - ログがごちゃついてきたから一括でプリフィックス付けたい。色変えたい。エラーだけファイルやサーバーに記録を残したい。が後から可能。
=> Debug.Log($"<color=#CC7700><b>[{nameof(MyOrg.App)}]</b></color> " + message);
- スタックトレースが無駄に長くならない。
- 一旦手を離れたモジュールからのログは非表示にしたい。
- リリースビルドではエラー以外は出力しない、とかできる。
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace MyOrg.App
{
internal static class Logger
{
[Conditional("UNITY_EDITOR")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Log(object message, Object context = null)
=> Debug.Log(message, context);
[Conditional("UNITY_EDITOR")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarning(object message, Object context = null)
=> Debug.LogWarning(message, context);
[Conditional("UNITY_EDITOR")]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError(object message, Object context = null)
=> Debug.LogError(message, context);
}
}
--
ロガーはロガーで色々と奥が深いみたいですが、本気のロガーに後から差し替えも可能でしょう。
以上です。お疲れ様でした。