Skip to content

Commit

Permalink
*tracking log error for each session user play
Browse files Browse the repository at this point in the history
  • Loading branch information
aprius committed Nov 19, 2022
1 parent 0d27a68 commit 59f37c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
29 changes: 20 additions & 9 deletions Runtime/Core/RuntimeManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Pancake.Monetization;
using System.Text;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Pancake
{
Expand All @@ -12,9 +11,10 @@ public static class RuntimeManager

private static bool mIsInitialized;

public static StringBuilder sessionLog;

#region Public API


public static event Action Initialized;

/// <summary>
Expand All @@ -27,16 +27,18 @@ public static class RuntimeManager
/// </summary>
public static void Init()
{
if (mIsInitialized)
{
return;
}
if (mIsInitialized) return;

if (Application.isPlaying)
{
// tracking log
sessionLog = new StringBuilder();
Application.logMessageReceived -= OnHandleLogReceived;
Application.logMessageReceived += OnHandleLogReceived;

// Initialize runtime Helper.
RuntimeHelper.Init();

var go = new GameObject("RuntimeManager");
Configure(go);

Expand All @@ -53,7 +55,16 @@ public static void Init()
Debug.Log("RuntimeManager has been initialized.");
}
}


private static void OnHandleLogReceived(string log, string stacktrace, LogType type)
{
if (type == LogType.Exception)
{
sessionLog.AppendLine(log);
sessionLog.AppendLine(stacktrace);
}
}

public static bool IsInitialized() { return mIsInitialized; }

/// <summary>
Expand Down
33 changes: 2 additions & 31 deletions Samples~/Feedback/Scripts/DebugLogCollector.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,13 @@
using System;
using System.Text;
using UnityEngine;
using System.Text;

namespace Pancake.Feedback
{
public class DebugLogCollector : FeedbackInfoCollector
{
private StringBuilder _log;

protected override void Awake()
{
base.Awake();
_log = new StringBuilder();
Application.logMessageReceived += HandleLog;
}

private void HandleLog(string logString, string stackTrace, LogType logType)
{
// enqueue the message
if (logType != LogType.Exception)
{
_log.AppendFormat("{0}: {1}", logType.ToString(), logString);
}
else
{
// don't add log type to exceptions, as it's already in the string
_log.AppendLine(logString);
}

// enqueue the stack trace
_log.AppendLine(stackTrace);
}


public override void Collect()
{
// attach log
byte[] bytes = Encoding.ASCII.GetBytes(_log.ToString());
byte[] bytes = Encoding.ASCII.GetBytes(RuntimeManager.sessionLog.ToString());
popupFeedback.report.AttachFile("log.txt", bytes);
}
}
Expand Down

0 comments on commit 59f37c9

Please sign in to comment.