Beispiel #1
0
        /// <summary>
        /// 处理unity log
        /// 注意,这里只用于向screen输出unity本身的log信息(就是Debug.Log)
        /// 不想screen输出时这里就不要使用
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="stack"></param>
        /// <param name="type"></param>
        private void MsgRec(string msg, string stack, UnityEngine.LogType type)
        {
            if (!LogConfig.BeShowLog)
            {
                return;
            }

            LogStruct logStruct = new LogStruct();

            logStruct.Msg = msg;

            logStruct.Tag = LogDefault.TAG_NAME_UNITY;

            logStruct.Time = LogUtils.GetCurTime();

            logStruct.Type = type;

            LogUtils.SB.Clear();

            logStruct.StackTrace = stack;

            switch (type)
            {
            case LogType.Error:
            case LogType.Assert:
            case LogType.Exception:
                logStruct.LogColor = LogColorEnum.red;
                break;

            case LogType.Warning:
                logStruct.LogColor = LogColorEnum.yellow;
                break;

            case LogType.Log:
                logStruct.LogColor = LogColorEnum.green;
                break;
            }

            if (LogConfig.BeWirte2Remote)
            {
                Buffer.Clear();

                Buffer.PutString(GetStringLog(logStruct));

                //Buffer.PutString("我");


                byte[] bs = Buffer.ToArray();

                //for (int i = 0; i < bs.Length; i++)
                //{
                //    Debug.Log("客户端发送i:"+i+"--->"+bs[i]);
                //}

                LogHttpClient.GetIns().Post((short)125, bs, null);
            }

            if (LogConfig.BeWrite2File)
            {
                byte[] bs = Buffer.ToArray();
                FileHelper.WriteBytes2File_Append(LogConfig.LogFileSavePath, bs);
            }


            LogDataMgr.AddLog(logStruct);

            RefreshCurLogList();
        }
Beispiel #2
0
        public static void I(string msg, string tag = LogDefault.TAG_NAME_DEFALUT, LogColorEnum color = LogColorEnum.green)
        {
            if (!LogConfig.BeShowLog)
            {
                return;
            }

            LogStruct logStruct = new LogStruct();

            logStruct.Msg      = msg;
            logStruct.Tag      = tag;
            logStruct.Time     = LogUtils.GetCurTime();
            logStruct.LogColor = color;
            logStruct.Type     = LogType.Log;
            LogUtils.SB.Clear();

            var stack  = new System.Diagnostics.StackTrace(true);
            var frames = stack.GetFrames();
            int length = frames.Length;

            for (int i = 0; i < length; i++)
            {
                string fileName = frames[i].GetFileName();
                fileName = System.IO.Path.GetFileName(fileName);
                var    method     = frames[i].GetMethod();
                Type   classType  = method.ReflectedType;
                string _nameSpace = classType.Namespace;
                string className  = classType.Name;
                string methodName = method.Name;
                int    lineNum    = frames[i].GetFileLineNumber();

                LogUtils.SB.Append(_nameSpace);
                LogUtils.SB.Append(".");
                LogUtils.SB.Append(className);
                LogUtils.SB.Append(":");
                LogUtils.SB.Append(methodName);
                LogUtils.SB.Append("()");
                LogUtils.SB.Append(" ( at ");
                LogUtils.SB.Append(fileName);
                LogUtils.SB.Append(":");
                LogUtils.SB.Append(lineNum);
                LogUtils.SB.Append("\n");
            }

            logStruct.StackTrace = LogUtils.SB.ToString();

            LogDataMgr.AddLog(logStruct);

            //NINFO 之所以screen console分开处理,因为MsgRec不能接收到tag,color等信息
            //这也是难点,所以要么输出到screen,要么到控制台,两者同时存在也没意义
            if (LogConfig.BeWrite2Screen)
            {
                Ins.RefreshCurLogList();

                if (LogConfig.BeWirte2Remote)
                {
                    Buffer.Clear();

                    Buffer.PutString(GetStringLog(logStruct));

                    //Buffer.PutString("我");


                    byte[] bs = Buffer.ToArray();

                    //for (int i = 0; i < bs.Length; i++)
                    //{
                    //    Debug.Log("客户端发送i:"+i+"--->"+bs[i]);
                    //}

                    LogHttpClient.GetIns().Post((short)125, bs, null);
                }

                if (LogConfig.BeWrite2File)
                {
                    byte[] bs = Buffer.ToArray();
                    FileHelper.WriteBytes2File_Append(LogConfig.LogFileSavePath, bs);
                }
            }
            else
            {
                Debug.Log(GetStringLog(logStruct));
            }
        }
Beispiel #3
0
        public static void E(string msg, string tag = LogDefault.TAG_NAME_DEFALUT, LogColorEnum color = LogColorEnum.red)
        {
            if (!LogConfig.BeShowLog)
            {
                return;
            }
            LogStruct logStruct = new LogStruct();

            logStruct.Msg      = msg;
            logStruct.Tag      = tag;
            logStruct.Time     = LogUtils.GetCurTime();
            logStruct.LogColor = color;
            logStruct.Type     = LogType.Error;

            LogUtils.SB.Clear();

            var stack  = new System.Diagnostics.StackTrace(true);
            var frames = stack.GetFrames();
            int length = frames.Length;

            for (int i = 0; i < length; i++)
            {
                string fileName = frames[i].GetFileName();
                fileName = System.IO.Path.GetFileName(fileName);
                var    method     = frames[i].GetMethod();
                Type   classType  = method.ReflectedType;
                string _nameSpace = classType.Namespace;
                string className  = classType.Name;
                string methodName = method.Name;
                int    lineNum    = frames[i].GetFileLineNumber();

                LogUtils.SB.Append(_nameSpace);
                LogUtils.SB.Append(".");
                LogUtils.SB.Append(className);
                LogUtils.SB.Append(":");
                LogUtils.SB.Append(methodName);
                LogUtils.SB.Append("()");
                LogUtils.SB.Append(" ( at ");
                LogUtils.SB.Append(fileName);
                LogUtils.SB.Append(":");
                LogUtils.SB.Append(lineNum);
                LogUtils.SB.Append("\n");
            }

            logStruct.StackTrace = LogUtils.SB.ToString();

            LogDataMgr.AddLog(logStruct);

            if (LogConfig.BeWrite2Screen)
            {
                Ins.RefreshCurLogList();

                if (LogConfig.BeWirte2Remote)
                {
                    Buffer.Clear();

                    Buffer.PutString(GetStringLog(logStruct));

                    byte[] bs = Buffer.ToArray();

                    LogHttpClient.GetIns().Post((short)125, bs, null);
                }

                if (LogConfig.BeWrite2File)
                {
                    byte[] bs = Buffer.ToArray();
                    FileHelper.WriteBytes2File_Append(LogConfig.LogFileSavePath, bs);
                }
            }
            else
            {
                //MsgRec 会做log文件保存,和向远程传送log,所以使用cosonle输出不用加这两项
                Debug.Log(GetStringLog(logStruct));
            }
        }