From e5b8496e1bd5fba62f2be0691b9c1507e85196aa Mon Sep 17 00:00:00 2001 From: ndesai-newrelic <89222514+ndesai-newrelic@users.noreply.github.com> Date: Tue, 8 Oct 2024 09:49:41 -0500 Subject: [PATCH] Logging docs readme (#31) * 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 --- .../Scripts/Native/NewRelicAndroid.cs | 30 +++++++++++++++++-- .../Scripts/Native/NewRelicIos.cs | 27 +++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs b/com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs index 09c2f09..fed3096 100644 --- a/com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs +++ b/com.newrelic.agent/Scripts/Native/NewRelicAndroid.cs @@ -4,6 +4,7 @@ using System.Text.RegularExpressions; using NewRelic.Utilities; using UnityEngine; +using static NewRelic.NewRelicAgent; namespace NewRelic.Native { @@ -564,8 +565,8 @@ public static void logMessageHandler(string logString, string stackTrace, LogTyp if (pluginInstance != null) { Dictionary attributes = new Dictionary(); - 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); @@ -785,7 +786,32 @@ public override void LogAttributes(Dictionary 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 \ No newline at end of file diff --git a/com.newrelic.agent/Scripts/Native/NewRelicIos.cs b/com.newrelic.agent/Scripts/Native/NewRelicIos.cs index e29f510..0b55622 100644 --- a/com.newrelic.agent/Scripts/Native/NewRelicIos.cs +++ b/com.newrelic.agent/Scripts/Native/NewRelicIos.cs @@ -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); @@ -784,6 +784,29 @@ public override void LogAttributes(Dictionary 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