示例#1
0
 public static void K(ELogTag tag, string format, params object[] args)
 {
     if (sLog != null)
     {
         sLog.Print(ELogLevel.Key, tag, format, args);
     }
 }
示例#2
0
        public static void WriteLine(ELogTag tag, string category, string format, params object[] args)
        {
            var str = System.String.Format(format, args);

            WriteLine(tag, category, str);
            OnReportLog?.Invoke(tag, category, format, args);
        }
示例#3
0
    /// 上报玩家行为数据
    public void UploadUserAction(string actionType, ELogTag eLogTag, string content, int elapsedTime = 0, int consumedBytes = 0)
    {
//         UploadMessage uploadMessage = new UploadMessage();
//         uploadMessage.ContextBefore = actionType;
//
//         LogMessage logMessage = new LogMessage();
//         logMessage.tag = eLogTag;
//         logMessage.content = content;
//         uploadMessage.RecordMessage = logMessage;
//
//         uploadMessage.ElaspedTime = elapsedTime;
//         uploadMessage.ConsumedBytes = consumedBytes;
//
//         Message uiMessage = new Message();
//         uiMessage.Callback = UploadUserActionCallBack;
//         uiMessage.Param = uploadMessage;
//         uiMessage.What = (int)MessageId.MsgUpdateUserAction;
//
//         _messageHandler.PostMessage(uiMessage);
    }
示例#4
0
 public string this[ELogTag tag]
 {
     set { Log((int)tag, value); }
 }
示例#5
0
 static public void UploadUserAction(string userActionType, ELogTag eLogTag, string content, int elapsedTime = 0, int consumedBytes = 0)
 {
     sLog.GetLogWriter().UploadUserAction(userActionType, eLogTag, content, elapsedTime, consumedBytes);
 }
示例#6
0
    public void Print(ELogLevel level, ELogTag tag, string format, params object[] args)
    {
        if (level < _logLevel)
        {
            return;
        }

        if (_logBitmap[(int)tag] == 0)
        {
            return;
        }

        string content = format;

        try
        {
            content = string.Format(format, args);
        }
        catch (Exception e)
        {
            content = e.ToString();
            level   = ELogLevel.Error;
        }

        {
            string sameStr = content.Substring(0, Mathf.Min(SUPPRESS_LOG_SAMPLE_CHAR_COUNT, content.Length));
            if (string.IsNullOrEmpty(_sameLogStr) || !sameStr.Equals(_sameLogStr))
            {
                _sameLogStr = sameStr;
                _sameLogCnt = 0;
            }
            else
            {
                _sameLogCnt++;
            }

            if (_sameLogCnt == SUPPRESS_LOG_MAX_LINE)
            {
                content = "<ignore duplicate log message>";
            }
            else if (_sameLogCnt > SUPPRESS_LOG_MAX_LINE)
            {
                return;
            }
        }

        LogMessage msg = null;

        if (_logWriter != null)
        {
            msg = _logWriter.GetMessage();
        }

        msg.time    = DateTime.Now;
        msg.level   = level;
        msg.tag     = tag;
        msg.content = content;

        lock (_logStringBuilder)
        {
            if (level >= LogConstant.PRINT_STACK_LEVEL)
            {
                // All print call contains 2 frame which in this file.
                StackTrace   stackTrace  = new StackTrace(2, true);
                StackFrame[] stackFrames = stackTrace.GetFrames();
                msg.stack = stackFrames;

                GetStackStr(_logStringBuilder, msg.stack);
                msg.stackStr = _logStringBuilder.ToString();
            }

            PackMessage(msg, _logStringBuilder);
        }

        // Output Log to file
        if (_logWriter != null)
        {
            _logWriter.AddMessage(msg);
        }

        if (level >= _logLevelConsole)
        {
            // Output Log console.
            PrintMessage(msg);
        }
    }
示例#7
0
 public void SetTagEnable(ELogTag tag, bool enabled)
 {
     _logBitmap[(int)tag] = (byte)(enabled ? 0x01 : 0x00);
 }
示例#8
0
 public static void WriteLine(ELogTag tag, string category, string info)
 {
     System.Diagnostics.Trace.WriteLine(info);
     OnReportLog?.Invoke(tag, category, info, null);
 }
示例#9
0
文件: CLogSys.cs 项目: yh821/Zombie
    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
    }
示例#10
0
文件: CLogSys.cs 项目: yh821/Zombie
 public static void Log(ELogLevel level, ELogTag tag, string content)
 {
     Log(level, tag, content, null);
 }