update: 更新 GuruReporter 捕获异常, 上报信息
parent
0a3c54e0a7
commit
1eef3d618c
|
|
@ -15,6 +15,7 @@ namespace Guru
|
||||||
public static void InitFirebase(Action callback, bool isDebug = false)
|
public static void InitFirebase(Action callback, bool isDebug = false)
|
||||||
{
|
{
|
||||||
_isDebug = isDebug;
|
_isDebug = isDebug;
|
||||||
|
GuruRepoter.Install();
|
||||||
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
|
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
|
||||||
DependencyStatus = task.Result;
|
DependencyStatus = task.Result;
|
||||||
if (DependencyStatus == DependencyStatus.Available)
|
if (DependencyStatus == DependencyStatus.Available)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9807dc50fb0f4127adc07b053dc5eac5
|
||||||
|
timeCreated: 1707044916
|
||||||
|
|
@ -0,0 +1,91 @@
|
||||||
|
namespace Guru
|
||||||
|
{
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Firebase.Crashlytics;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class GuruRepoter
|
||||||
|
{
|
||||||
|
private static bool _isReady;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 捕获列表
|
||||||
|
/// </summary>
|
||||||
|
private static List<LogType> _catchFilter = new List<LogType>()
|
||||||
|
{
|
||||||
|
LogType.Exception,
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 上报列表
|
||||||
|
/// </summary>
|
||||||
|
private static List<LogType> _logFilter = new List<LogType>()
|
||||||
|
{
|
||||||
|
LogType.Error,
|
||||||
|
LogType.Assert,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static void Install()
|
||||||
|
{
|
||||||
|
_isReady = true;
|
||||||
|
Crashlytics.IsCrashlyticsCollectionEnabled = true;
|
||||||
|
|
||||||
|
Application.logMessageReceived += OnReceivedMessage;
|
||||||
|
Application.logMessageReceivedThreaded += OnReceivedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CheckReady()
|
||||||
|
{
|
||||||
|
if (_isReady) return;
|
||||||
|
Install();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static string ToLogTypeString(LogType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case LogType.Exception: return "ex";
|
||||||
|
case LogType.Error: return "e";
|
||||||
|
case LogType.Warning: return "w";
|
||||||
|
}
|
||||||
|
return "i";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void OnReceivedMessage(string condition, string stackTrace, LogType type)
|
||||||
|
{
|
||||||
|
|
||||||
|
string msg = $"{DateTime.Now:yy-MM-dd HH:mm:ss} [{ToLogTypeString(type)}] {condition}\n{stackTrace}";
|
||||||
|
|
||||||
|
if (_catchFilter.Contains(type))
|
||||||
|
{
|
||||||
|
LogException(msg);
|
||||||
|
}
|
||||||
|
else if(_logFilter.Contains(type))
|
||||||
|
{
|
||||||
|
Log(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LogException(Exception ex)
|
||||||
|
{
|
||||||
|
CheckReady();
|
||||||
|
Crashlytics.LogException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void LogException(string msg)
|
||||||
|
{
|
||||||
|
CheckReady();
|
||||||
|
Crashlytics.LogException(new Exception(msg));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Log(string msg)
|
||||||
|
{
|
||||||
|
CheckReady();
|
||||||
|
Crashlytics.Log(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 99041f4e2a234d89b79af4a0d23514d2
|
||||||
|
timeCreated: 1707038494
|
||||||
Loading…
Reference in New Issue