1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 15:18:25 -05:00
UDRIGEEKCup2024/Assets/Scripts/Logging/GlobalLogConfig.cs

41 lines
1.5 KiB
C#
Raw Normal View History

using System.IO;
using Unity.Logging;
using Unity.Logging.Internal.Debug;
using Unity.Logging.Sinks;
using UnityEngine;
using Logger = Unity.Logging.Logger;
namespace MAVRIC.GEEKCup.Logging
{
[DefaultExecutionOrder(-1000)]
public class GlobalLogConfig : MonoBehaviour
{
[SerializeField] private LogLevel editorConsoleMinimalLogLevel = LogLevel.Verbose;
[SerializeField] private string fileName = "LogOutput.log";
[SerializeField] private LogLevel fileMinimalLogLevel = LogLevel.Verbose;
[SerializeField] private string outputTemplate = "[{Level}] [{Timestamp}] {Message}";
private void Awake()
{
var dataPath = Application.dataPath;
#if UNITY_EDITOR
dataPath = Path.Combine(dataPath, "..");
#endif
var fullPath = Path.Join(dataPath, fileName);
Log.Logger = new Logger(new LoggerConfig()
.MinimumLevel.Debug()
.WriteTo.UnityDebugLog(minLevel: editorConsoleMinimalLogLevel, outputTemplate: outputTemplate)
.WriteTo.File(fullPath, minLevel: fileMinimalLogLevel, formatter: LogFormatterJson.Formatter)
.WriteTo.StdOut(outputTemplate: outputTemplate));
SelfLog.SetMode(SelfLog.Mode.EnabledInUnityEngineDebugLogError);
Log.Verbose("GlobalLogConfig Started...", gameObject);
}
}
}