public override void SysInitial() { base.SysInitial(); Instance = this; mLogPlatform = new CLogPlatformEditor(); System.DateTime now = System.DateTime.Now; mLogDirPath = "Log"; mLogFilePath = string.Format("{6}/{0:00}{1:00}{2:00}{3:00}{4:00}{5:00}.log", now.Year - 2000, now.Month, now.Day, now.Hour, now.Minute, now.Second, mLogDirPath); //DeleteOldLog(); OpenLogFile(); Log(ELogLevel.Verbose, ELogTag.LogSys, string.Format("Start Log {0}", mLogFilePath)); }
public static void Log(ELogLevel level, ELogTag tag, string content, string stack) { CLogSys logSys = CGameRoot.GetGameSystem <CLogSys>(); if (logSys == null) { return; } if ((int)level < (int)logSys.mSelfLogLevel) { return; } //if (FightScene.mInstance != null && FightScene.mInstance.isBattleStart) //{ // return; //} #region 重复内容保护 string sameStr = content.Substring(0, Mathf.Min(20, content.Length)); if (string.IsNullOrEmpty(mSameLogStr) || mSameLogStr != sameStr) { mSameLogStr = sameStr; mSameLogCnt = 0; } else { mSameLogCnt++; } if (mSameLogCnt > 20) { return; } #endregion #if !UNITY_EDITOR if (string.IsNullOrEmpty(stack)) { System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true); System.Diagnostics.StackFrame[] stackFrames = stackTrace.GetFrames(); System.Text.StringBuilder sb = new System.Text.StringBuilder(); for (int i = 0; i < stackFrames.Length; ++i) { System.Reflection.MethodBase method = stackFrames[i].GetMethod(); string typeName = method.DeclaringType.FullName; string methodName = method.Name; if (typeName == "CLogSys" || typeName == "UnityEngine.Debug" || methodName == "CallLogCallback") { continue; } sb.AppendFormat("{0}:{1}\n", typeName, methodName); } stack = sb.ToString(); } char[] contentInLine; int contentIdx; TransInLine(content, out contentInLine, out contentIdx); char[] stackInLine; int stackIdx; TransInLine(stack, out stackInLine, out stackIdx); System.DateTime now = System.DateTime.Now; string curTime = string.Format("{0:00}{1:00}{2:00}{3:00}{4:00}", now.Month, now.Day, now.Hour, now.Minute, now.Second); string logStr = string.Format("{0}|{1}|{2}|{3}|{4}|{5}", cLogPrefix, curTime, level.ToString()[0], tag, new string(contentInLine, 0, contentIdx), new string(stackInLine, 0, stackIdx)); //ELogLevel logLevel = (ResourceSys != null && ResourceSys.RootCfg != null) ? ResourceSys.RootCfg.mLogLevel : ELogLevel.Debug; if (mLogPlatform != null) { mLogPlatform.Log(logStr); } if (level >= ELogLevel.Error) { //DCProxy.ReportError(content, logStr); } #else if (level == ELogLevel.Warning) { Debug.LogWarning(content); } else if (level == ELogLevel.Error) { Debug.LogError(content); } else if (level == ELogLevel.Fatal) { Debug.LogError(content); } else if (level == ELogLevel.Debug) { Debug.LogWarning(content); } else if (level == ELogLevel.Verbose) { Debug.Log(content); } #endif }