Skip to content

Commit

Permalink
Logging docs readme (#31)
Browse files Browse the repository at this point in the history
* feat: Log Forwarding and ANR reporting through android sdk.

* fix: log attributes method is throwing expection in android

* fix: expection Error for Unity Auto Instrument Logs

* fix: expection Error for Unity Auto Instrument Logs
  • Loading branch information
ndesai-newrelic authored Oct 8, 2024
1 parent f29d5c9 commit e5b8496
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
30 changes: 28 additions & 2 deletions com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text.RegularExpressions;
using NewRelic.Utilities;
using UnityEngine;
using static NewRelic.NewRelicAgent;

namespace NewRelic.Native
{
Expand Down Expand Up @@ -564,8 +565,8 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp
if (pluginInstance != null)
{
Dictionary<string, object> attributes = new Dictionary<string, object>();
attributes.Add("level", type.ToString());
attributes.Add("log", logString);
attributes.Add("level", ConvertUnityLogTypesToNewRelicLogType(type));
attributes.Add("message", logString);
if (stackTrace.Length > 0)
{
attributes.Add("stacktrace", stackTrace);
Expand Down Expand Up @@ -785,7 +786,32 @@ public override void LogAttributes(Dictionary<string, object> attributes)
AndroidJavaObject javaMap = CreateJavaMapFromDictionary(attributes);
pluginInstance.CallStatic("logAttributes", javaMap);
}

static String ConvertUnityLogTypesToNewRelicLogType(LogType type)
{
String logLevel = "INFO";

if (type.Equals(LogType.Assert))
{
logLevel = "VERBOSE";
}else if (type.Equals(LogType.Log))
{
logLevel = "INFO";
}
else if (type.Equals(LogType.Warning))
{
logLevel = "WARN";
}
else if (type.Equals(LogType.Error))
{
logLevel = "ERROR";
}

return logLevel;
}
}


}

#endif
27 changes: 25 additions & 2 deletions com.newrelic.agent/Scripts/Native/NewRelicIos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,9 +621,9 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp
var attributes = NR_dictionaryCreate();


NR_dictionaryInsertString(attributes, "log", logString);
NR_dictionaryInsertString(attributes, "message", logString);
NR_dictionaryInsertString(attributes, "stacktrace", stackTrace);
NR_dictionaryInsertString(attributes, "logLevel", type.ToString());
NR_dictionaryInsertString(attributes, "logLevel", ConvertUnityLogTypesToNewRelicLogType(type));

NR_logAttributes(attributes);

Expand Down Expand Up @@ -784,6 +784,29 @@ public override void LogAttributes(Dictionary<string, object> attributes)
System.IntPtr NSDict = CreateNSDictionaryFromDictionary(attributes);
NR_logAttributes(NSDict);
}

static String ConvertUnityLogTypesToNewRelicLogType(LogType type)
{
String logLevel = "INFO";

if (type.Equals(LogType.Assert))
{
logLevel = "VERBOSE";
}else if (type.Equals(LogType.Log))
{
logLevel = "INFO";
}
else if (type.Equals(LogType.Warning))
{
logLevel = "WARN";
}
else if (type.Equals(LogType.Error))
{
logLevel = "ERROR";
}

return logLevel;
}
}

internal class StackFrame
Expand Down

0 comments on commit e5b8496

Please sign in to comment.