日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

unity 日志级别_【Unity】通用的Debugger日志模块

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 unity 日志级别_【Unity】通用的Debugger日志模块 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

usingSystem;usingSystem.IO;namespaceUnityEngine

{///

///系統日志模塊///

public classDebugger

{public static bool EnableLog; //是否啟用日志,僅可控制普通級別的日志的啟用與關閉,LogError和LogWarn都是始終啟用的。

public static bool EnableTime = true;public static bool EnableSave = false; //是否允許保存日志,即把日志寫入到文件中

public static bool EnableStack = false;public static string LogFileDir = Application.persistentDataPath + "/DebuggerLog/";public static string LogFileName = "";public static string Prefix = ">"; //用于與Unity默認的系統日志做區分。本日志系統輸出的日志頭部都會帶上這個標記。

public static StreamWriter LogFileWriter = null;public static boolUseUnityEngine;private static string GetLogText(string tag, stringmessage)

{string str = "";if(EnableTime)

{

str= DateTime.Now.ToString("HH:mm:ss.fff") + " ";

}return (str + tag + "::" +message);

}private static stringGetLogTime()

{string str = "";if(EnableTime)

{

str= DateTime.Now.ToString("HH:mm:ss.fff") + " ";

}returnstr;

}public static void Log(objectmessage)

{if (!Debugger.EnableLog)return;string str = GetLogTime() +message;

Debug.Log(Prefix+ str, null);

LogToFile("[I]" + str, false);

}public static void Log(objectmessage, Object context)

{if (!Debugger.EnableLog)return;string str = GetLogTime() +message;

Debug.Log(Prefix+str, context);

LogToFile("[I]" + str, false);

}public static void Log(string tag, stringmessage)

{if (!Debugger.EnableLog)return;

message=GetLogText(tag, message);

Debug.Log(Prefix+ message, null);

LogToFile("[I]" + message, false);

}public static void Log(string tag, string format, params object[] args)

{if (!Debugger.EnableLog)return;string logText = GetLogText(tag, string.Format(format, args));

Debug.Log(Prefix+ logText, null);

LogToFile("[I]" + logText, false);

}public static void LogError(objectmessage)

{string str = GetLogTime() +message;

Debug.Log(Prefix+ str, null);

LogToFile("[E]" + str, true);

}public static void LogError(objectmessage, Object context)

{string str = GetLogTime() +message;

Debug.Log(Prefix+str, context);

LogToFile("[E]" + str, true);

}public static void LogError(string tag, stringmessage)

{

message=GetLogText(tag, message);

Debug.Log(Prefix+ message, null);

LogToFile("[E]" + message, true);

}public static void LogError(string tag, string format, params object[] args)

{string logText = GetLogText(tag, string.Format(format, args));

Debug.Log(Prefix+ logText, null);

LogToFile("[E]" + logText, true);

}///

///將日志寫入到文件中///

///

///

private static void LogToFile(string message, bool EnableStack = false)

{if (!Debugger.EnableSave)return;if (LogFileWriter == null)

{

LogFileName= DateTime.Now.GetDateTimeFormats('s')[0].ToString();

LogFileName= LogFileName.Replace("-", "_");

LogFileName= LogFileName.Replace(":", "_");

LogFileName= LogFileName.Replace(" ", "");

LogFileName= LogFileName + ".log";if (string.IsNullOrEmpty(LogFileDir))

{try{if(UseUnityEngine)

{

LogFileDir= Application.persistentDataPath + "/DebuggerLog/";

}else{

LogFileDir= AppDomain.CurrentDomain.BaseDirectory + "/DebuggerLog/";

}

}catch(Exception exception)

{

Debug.Log(Prefix+ "獲取 Application.persistentDataPath 報錯!" + exception.Message, null);return;

}

}string path = LogFileDir +LogFileName;try{if (!Directory.Exists(LogFileDir))

{

Directory.CreateDirectory(LogFileDir);

}

LogFileWriter=File.AppendText(path);

LogFileWriter.AutoFlush= true;

}catch(Exception exception2)

{

LogFileWriter= null;

Debug.Log("LogToCache()" + exception2.Message + exception2.StackTrace, null);return;

}

}if (LogFileWriter != null)

{try{

LogFileWriter.WriteLine(message);if ((EnableStack || Debugger.EnableStack) &&UseUnityEngine)

{

LogFileWriter.WriteLine(StackTraceUtility.ExtractStackTrace());

}

}catch(Exception)

{

}

}

}public static void LogWarning(objectmessage)

{string str = GetLogTime() +message;

Debug.Log(Prefix+ str, null);

LogToFile("[W]" + str, false);

}public static void LogWarning(objectmessage, Object context)

{string str = GetLogTime() +message;

Debug.Log(Prefix+str, context);

LogToFile("[W]" + str, false);

}public static void LogWarning(string tag, stringmessage)

{

message=GetLogText(tag, message);

Debug.Log(Prefix+ message, null);

LogToFile("[W]" + message, false);

}public static void LogWarning(string tag, string format, params object[] args)

{string logText = GetLogText(tag, string.Format(format, args));

Debug.Log(Prefix+ logText, null);

LogToFile("[W]" + logText, false);

}

}

}

總結

以上是生活随笔為你收集整理的unity 日志级别_【Unity】通用的Debugger日志模块的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。