/*
 * @Author: Five
 * @Date: 2020-09-03 18:08:32
 * @Description:  日志 - 为了接管Unity的所有日志, 通过控制一下的两个方法, 即可完全控制log
 */

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Giant.Common;
using Giant.Resource;
using UnityEngine;

public class DbtLogHandler : ILogHandler
{
    private ILogHandler m_DefaultLogHandler = UnityEngine.Debug.unityLogger.logHandler;

    public bool EnableLog = false;

    public DbtLogHandler()
    {
        UnityEngine.Debug.unityLogger.logHandler = this;
#if DISABLED_LOG
        EnableLog = false;
#endif
    }

    public void LogException(Exception exception, UnityEngine.Object context)
    {
        if (EnableLog)
            m_DefaultLogHandler.LogException(exception, context);
    }

    public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
    {
        if (logType == LogType.Error)
        {
            format = "<color=red>" + format + "</color>";
        }
        if (EnableLog)
            m_DefaultLogHandler.LogFormat(logType, context, format, args);
    }
}
