NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Framework/Log/NativeLog.cs

75 lines
2.0 KiB
C#

using System.Collections.Generic;
using PhxhSDK;
namespace Code.Scripts.Framework.Log
{
public class NativeLog
{
private static NativeLog _instance;
public static NativeLog instance
{
get
{
if (_instance == null)
{
_instance = new NativeLog();
}
return _instance;
}
}
private Dictionary<int, NativeLogInst> _logInstDict = new Dictionary<int, NativeLogInst>();
public string logTimeFormat = "yyyy-MM-dd HH:mm:ss";
public string logTime { get; private set; }
private NativeLog()
{
_UpdateLogTime();
MonoHelper.instance.AddAction(EActionType.LATE_UPDATE, _UpdateLogTime);
}
private void _UpdateLogTime()
{
logTime = System.DateTime.Now.ToString(logTimeFormat);
}
public NativeLogInst BeginRecord(int logType, string specificName = "")
{
if (_logInstDict.ContainsKey(logType))
{
_logInstDict[logType].Stop();
}
else
{
if (string.IsNullOrEmpty(specificName))
{
specificName = "LogType_" + logType;
}
_logInstDict[logType] = new NativeLogInst(specificName);
}
return _logInstDict[logType];
}
public void Record(int logType,
string logContent)
{
if (!_logInstDict.TryGetValue(logType, out var logInst))
{
logInst = BeginRecord(logType);
}
logInst.Log(logContent);
}
public void EndRecord(int logType)
{
if (_logInstDict.TryGetValue(logType, out var logInst))
{
logInst.Stop();
_logInstDict.Remove(logType);
}
}
}
}