update: 更新 GuruReporter 捕获异常, 上报信息

deeplink
胡宇飞 2024-02-04 19:10:42 +08:00
parent 0a3c54e0a7
commit 1eef3d618c
4 changed files with 98 additions and 0 deletions

View File

@ -15,6 +15,7 @@ namespace Guru
public static void InitFirebase(Action callback, bool isDebug = false)
{
_isDebug = isDebug;
GuruRepoter.Install();
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWithOnMainThread(task => {
DependencyStatus = task.Result;
if (DependencyStatus == DependencyStatus.Available)

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9807dc50fb0f4127adc07b053dc5eac5
timeCreated: 1707044916

View File

@ -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);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 99041f4e2a234d89b79af4a0d23514d2
timeCreated: 1707038494