Ejemplo n.º 1
0
        //把所有的日志都保存起来
        private static void OnLogCallback(string condition, string stackTrace, LogType type)
        {
            if (logWritter == null)
            {
                string filePath = "";
                var    logName  = "/log_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".log";
                switch (Application.platform)
                {
                case RuntimePlatform.Android:
                case RuntimePlatform.IPhonePlayer:
                    filePath = string.Format("{0}/{1}", Application.persistentDataPath, logName);
                    break;

                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                case RuntimePlatform.OSXEditor:
                    filePath = string.Format("{0}/../logs/{1}", Application.dataPath, logName);
                    break;

                default:
                    filePath = string.Format("{0}/{1}", Application.persistentDataPath, logName);
                    break;
                }

                logWritter = new LogFileRecorder(filePath, FileMode.Append);
            }

            var time = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");

            //Environment.StackTrace是非常完整的堆栈包括Unity底层调用栈,而stackTrace只有exception才有堆栈,对于Log/LogWarning/LogError是没有堆栈,可以通过StackTrace加上堆栈 by qingqing.zhao test in unity2019.3.7
            // logWritter.WriteLine(string.Format("[{0}][{1}]{2}\n{3}", time, type, condition,  !string.IsNullOrEmpty(stackTrace)?stackTrace :Environment.StackTrace));
            //logWritter.WriteLine(string.Format("[{0}][{1}]{2}\n{3}", time, type, condition,  Environment.StackTrace ));
            logWritter.WriteLine(string.Format("[{0}][{1}]{2}\n{3}", time, type, condition, stackTrace));
        }
Ejemplo n.º 2
0
        //把Unity所有的日志都保存起来
        private static void OnLogCallback(string condition, string stackTrace, LogType type)
        {
            if (logWritter == null)
            {
                string filePath = "";
                var    logName  = "/log_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss") + ".log";
                switch (Application.platform)
                {
                case RuntimePlatform.Android:
                case RuntimePlatform.IPhonePlayer:
                    filePath = string.Format("{0}/{1}", Application.persistentDataPath, logName);
                    break;

                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                case RuntimePlatform.OSXEditor:
                    filePath = string.Format("{0}/../logs/{1}", Application.dataPath, logName);
                    break;

                default:
                    filePath = string.Format("{0}/{1}", Application.persistentDataPath, logName);
                    break;
                }
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                {
                    Directory.CreateDirectory(filePath);
                }
                logWritter = new LogFileRecorder(filePath, FileMode.Append);
            }

            //NOTE System.Environment.StackTrace是非常完整的堆栈包括Unity底层调用栈,而stackTrace只有exception才有堆栈,对于Log/LogWarning/LogError都是没有堆栈,可以通过StackTrace加上堆栈。 by qingqing.zhao test in unity2019.3.7
            logWritter.WriteLine(string.Format("{0}\n{1}", condition, stackTrace));
        }
Ejemplo n.º 3
0
        public static void WriteProfileLog(string logType, string line)
        {
            LogFileRecorder logger;

            if (!loggers.TryGetValue(logType, out logger))
            {
                logger = new LogFileRecorder(Application.persistentDataPath + "/profiler_" + logType + ".csv");
                loggers.Add(logType, logger);

                if (logType == "UI")
                {
                    logger.WriteLine("UI Name,Operation,Cost(ms)");
                }
                else
                {
                    logger.WriteLine("");
                }
            }

            logger.WriteLine(line);
        }
Ejemplo n.º 4
0
        public static void WriteLoadAbLog(string abName, float time)
        {
            LogFileRecorder logger;
            var             logType = "loadab";

            if (!loggers.TryGetValue(logType, out logger))
            {
                logger = new LogFileRecorder(Application.persistentDataPath + $"/profiler_loadab_{DateTime.Now.ToString("yyyy-M-d HH.mm.ss")}.csv");
                loggers.Add(logType, logger);
                logger.WriteLine("AB资源,耗时");
            }

            logger.WriteLine(string.Format("{0},{1:0.###}", abName, time));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 保存UI的一些数据到文件中
        /// </summary>
        public static void WriteUILog(string uiName, UIState state, float time)
        {
            LogFileRecorder logger;
            var             logType = "ui";

            if (!loggers.TryGetValue(logType, out logger))
            {
                logger = new LogFileRecorder(Application.persistentDataPath + $"/profiler_ui_{DateTime.Now.ToString("yyyy-M-d HH.mm.ss")}.csv");
                loggers.Add(logType, logger);
                logger.WriteLine("UI名字,操作(函数),耗时(ms)");
            }

            logger.WriteLine(string.Format("{0},{1},{2:0.###}", uiName, state, time));
        }
Ejemplo n.º 6
0
        //把Unity所有的日志都保存起来
        private static void OnLogCallback(string condition, string stackTrace, LogType type)
        {
            if (logWritter == null)
            {
                string filePath = GetLogFilePath();
                if (!Directory.Exists(Path.GetDirectoryName(filePath)))
                {
                    Directory.CreateDirectory(filePath);
                }
                logWritter = new LogFileRecorder(filePath, FileMode.Append);
            }

            //NOTE System.Environment.StackTrace是非常完整的堆栈包括Unity底层调用栈,而stackTrace只有exception才有堆栈,对于Log/LogWarning/LogError都是没有堆栈,可以通过StackTrace加上堆栈。 by qingqing.zhao test in unity2019.3.7
            logWritter.WriteLine(string.Format("{0}\n{1}", condition, stackTrace));
        }