/// <summary> /// 设置glog 属性 /// </summary> public static void SetGLogProperty(string key, string v) { if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(v)) { return; } bool isActive = v == "1"; switch (key) { case "IsAllLogEnabled": GLog.SetAllLogEnabled(isActive); return; case "IsLogStackTraceEnabled": GLog.SetLogStackTraceEnabled(isActive); return; case "IsLogInfoEnabled": GLog.SetLogInfoEnabled(isActive); return; case "IsLogWarningEnabled": GLog.SetLogWarningEnabled(isActive); return; case "IsLogErrorEnabled": GLog.SetLogErrorEnabled(isActive); return; case "IsLogToConsoleEnabled": GLog.SetLogToConsoleEnabled(isActive); return; case "IsLogToFileEnabled": GLog.SetLogToFileEnabled(isActive); return; case "IsOpenIosNSLog": #if UNITY_IPHONE if (isActive) { GLog.SetCallLogBack(CallLogBack); } #endif return; } }
/// <summary> /// init 操作 默认会去 Path.Combine(Application.persistentDataPath, "GlogCtrl.txt") /// 找配置如果找不到 采用 编译配置 方便在出包后动态调整日志输出权限 /// </summary> public static void Init() { if (_isInit) { return; } var logConfigUrl = Path.Combine(Application.persistentDataPath, "GlogCtrl.txt"); ///如果是编辑器模式 则直接读取 Path.Combine(Application.streamingAssetsPath, "GlogCtrl.txt") 文件 if (Application.isEditor) { logConfigUrl = Path.Combine(Application.streamingAssetsPath, "GlogCtrl.txt"); } if (File.Exists(logConfigUrl)) { try { using (var sr = OpenReadText(logConfigUrl)) { string item; string[] attr = null; while (!sr.EndOfStream) { item = sr.ReadLine(); if (string.IsNullOrEmpty(item) || item.IndexOf("|") == -1) { continue; } attr = item.Split('|'); SetGLogProperty(attr[0], attr[1]); } } } catch (Exception e) { if (GLog.IsLogErrorEnabled) { GLog.LogException(e); } goto GlogDefault; } GLog.Init(); _isInit = true; return; } GlogDefault: if (GLog.IsLogInfoEnabled) { GLog.LogInfo("Glog 编译设置"); } #if DISABLE_LOG_ALL GLog.SetAllLogEnabled(false); #endif #if DISABLE_LOG_INFO GLog.SetLogInfoEnabled(false); #endif #if DISABLE_LOG_WARN GLog.SetLogWarningEnabled(false); #endif #if DISABLE_LOG_ERROR GLog.SetLogErrorEnabled(false); #endif #if DISABLE_LOG_CONSOLE GLog.SetLogToConsoleEnabled(false); #endif #if DISABLE_LOG_STACKTRACE GLog.SetLogStackTraceEnabled(false); #endif #if UNITY_IPHONE GLog.SetCallLogBack(CallLogBack); #endif #if !(DEVELOPMENT_BUILD || UNITY_EDITOR || ALWAYS_SHOW_LOG || DEBUG) GLog.SetCallLogBack(null); GLog.SetLogToConsoleEnabled(false); GLog.SetLogInfoEnabled(false); GLog.SetLogStackTraceEnabled(false); #endif GLog.Init(); _isInit = true; }