It’s common to face issues with mobile apps. With Build and Run time logs we can gather more details about the errors or crashes. The same can be shared with New Relic support team when you log a ticket which provides deeper insights into the issue you are facing.
Here’s a quick post on how to increase the New Relic Mobile agent logging level and collect the logs.
For iOS apps
Let’s see how we can collect the Build and Run-time logs for iOS apps.
Build Logs - iOS
In Xcode, to view the build log, click on the last icon (text bubble) in the Navigator area located in the top left panel.
Then click on ‘Build’ under the app name to view the build log. You can then save the complete build log in a .txt file just by clicking on Save button (top right corner) from the same page.
Runtime logs - iOS
To increase the logging level
Six log levels are available for mobile apps monitoring:
To increase your logging level in the app, add the following method in your app delegate file :
Just before calling
AppDelegate.m , add:
Just before calling
AppDelegate.swift , add:
After these settings, please make sure to clean build the code to reflect the new changes.
From your app simulator window, click
Debug -> Open System Log, which opens a Console.
We can see the complete run time log in the Console as shown below.
Clicking on the Reveal button (top-left) will open it in the Finder and shows you where the original file is located.
For Android apps
We can gather build time logs and run time logs for Android apps as well.
Build Logs - Android
Use below command in the terminal, at the root level of your project folder.
./gradlew --stop && ./gradlew --debug --no-daemon --refresh-dependencies clean assembleRelease > buildLog.txt
If you are running debug or some other variant, change the
assembleRelease of the command to your situation.
From Android Studio, you can run this in the inbuilt Terminal as shown below.
The same build log is saved as buildLog.txt in the same path where the above command was run.
Runtime Logs - Android
To increase the agent logging level
There are six log levels.
AUDIT is the most verbose, set the log level to
AUDIT in the default/main activity file where New Relic is initialized.
Code example below.
NewRelic.withApplicationToken("YOUR_APP_TOKEN") .withLogLevel(AgentLog.AUDIT) .start(this.getApplication());
After setting the log level to
AUDIT, build and run to reproduce the error or any crash you are facing.
In Android Studio, you can find the runtime logs in the Logcat window.
You can also collect the runtime log from Terminal by running the command
adb logcat > logcat.txt &
But before running adb command, make sure the path is set to platform-tools in Android SDK library.
If you are interested to learn more on working with logs, please feel free to check the below document from Android.