//把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)); }
//把所有的日志都保存起来 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)); }
void OnApplicationQuit() { IsApplicationQuit = true; IsAppPlaying = false; if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.OSXPlayer) { LogFileManager.Destory(); } LogFileRecorder.CloseStream(); }
public static void WriteProfileLog(string logType, string line) { LogFileRecorder logger; if (!loggers.TryGetValue(logType, out logger)) { logger = new LogFileRecorder(Application.persistentDataPath + $"/profiler_{logType}_{DateTime.Now.ToString("yyyy-M-d HH.mm.ss")}.csv"); loggers.Add(logType, logger); } logger.WriteLine(line); }
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)); }
/// <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)); }
//把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)); }
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); }
void OnApplicationQuit() { LogFileRecorder.CloseStream(); }
private IEnumerator LoadAssetBundle(string relativeUrl) { #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 Manifest中管理了依赖 var abPath = relativeUrl.ToLower(); var deps = _assetBundleManifest.GetAllDependencies(abPath); _depLoaders = new AssetBundleLoader[deps.Length]; for (var d = 0; d < deps.Length; d++) { var dep = deps[d]; _depLoaders[d] = AssetBundleLoader.Load(dep, null, _loaderMode); if (_depLoaders[d].dependFrom == string.Empty) { _depLoaders[d].dependFrom = relativeUrl; } } for (var l = 0; l < _depLoaders.Length; l++) { var loader = _depLoaders[l]; while (!loader.IsCompleted) { yield return(null); } } #endif #if UNITY_5 || UNITY_2017_1_OR_NEWER // Unity 5 AssetBundle自动转小写 relativeUrl = relativeUrl.ToLower(); #endif if (AppConfig.IsLogAbLoadCost) { beginTime = Time.realtimeSinceStartup; } string _fullUrl = KResourceModule.GetAbFullPath(relativeUrl); if (string.IsNullOrEmpty(_fullUrl)) { OnFinish(null); yield break; } AssetBundle assetBundle = null; if (_loaderMode == LoaderMode.Sync) { assetBundle = AssetBundle.LoadFromFile(_fullUrl); } else { var request = AssetBundle.LoadFromFileAsync(_fullUrl); while (!request.isDone) { if (IsReadyDisposed) // 中途释放 { OnFinish(null); yield break; } Progress = request.progress; yield return(null); } assetBundle = request.assetBundle; } if (assetBundle == null) { Log.Error("assetBundle is NULL: {0}", RelativeResourceUrl); } if (AppConfig.IsLogAbLoadCost) { Log.Info("[Finish] Load AssetBundle {0}, CostTime {1}s {2}", relativeUrl, Time.realtimeSinceStartup - beginTime, dependFrom); } if (AppConfig.IsSaveCostToFile && !relativeUrl.StartsWith("ui/")) { LogFileRecorder.WriteLoadAbLog(relativeUrl, Time.realtimeSinceStartup - beginTime); } OnFinish(assetBundle); }
void OnApplicationQuit() { IsApplicationQuit = true; LogFileRecorder.CloseStream(); }