Device logs
nRF Cloud Alerts and Logs have been replaced by Memfault Trace Events. For
further information on how to migrate, see the
Migrate nRF Cloud Alerts to Memfault Trace Events
guide.
Device logs are visible in the nRF Cloud portal or APIs.
This guide includes steps for both JSON-based and binary logs.
Requirements
- An nRF91 Series device
- One of the supported samples. These samples are preconfigured to support nRF Cloud logs.
If you would like to use binary logs, see the Overview for links to documentation on requirements and configuration. You can download binary logs through the nRF Cloud portal or APIs.
Using device logs in the nRF Cloud portal
To enable, disable, or change the level of logs:
-
Log in to the nRF Cloud portal.
-
Select Device Management in the left sidebar.
A pane opens to the right.
-
Select Devices.
-
Click the name of the device you want to view.
The device page opens.
-
Find the Logs card.
The header of the Logs card shows the current log level.
-
Select the desired log level from the drop-down menu.
It may take some time for the log level change request to finish processing. If the device is not connected when you change the log level in the portal, it will process the change request when it reconnects to nRF Cloud.
Once the request finishes processing, the current log level updates to match the requested one.
Viewing logs
To view logs and download data:
-
From the device page, find the Logs card.
If the device is currently connected, the card shows current logs.
To view historical log data:
-
Click the triangular clock icon in the lower right corner of the Logs card.
The time selector opens.
-
Select a time range from the drop-down menu.
-
Click Get data.
Logs within the specified time range appear in the card. Click the cloud icon to download logs for that range as a CSV file.
Messages in logs might not be in chronological order.
Downloading binary logs through the portal
Verify that your device is configured to use binary logs:
-
Log in to the nRF Cloud portal.
-
Select Device Management in the left sidebar.
A panel opens to the right.
-
Select Devices.
-
Click the name of the device you want to view.
The device page opens.
-
Find the Device Information card.
-
Expand the Service info section.
-
Verify that the UI section includes DICTLOG to confirm that your device is configured for binary logs.
To download binary logs for a device:
-
Select Device Management in the left sidebar.
A panel opens to the right.
-
Select Devices.
-
Click the name of the device you want to view.
The device page opens.
-
Find the Logs card.
-
Click the Download binary logs button.
The Binary Logs pop-up opens.
-
Select a time range. The start time must be in the past 30 days, and the end time may be up to 24 hours after the specified start. The portal displays an error if you select an invalid time range.
You can enter the time range manually, or click the calendar icon to select start and end dates.
If you do not specify a time range, the file will contain logs from the last 24 hours.
-
Click Download.
A file downloads containing binary logs.
-
Parse the binary log file.
Using device logs through the APIs
Device messages with log data are sent over
supported message topics or through the
SendDeviceMessage
endpoint. Messages are stored on nRF Cloud for 30 days.
Binary log messages are sent over the d2c/bin topic.
To enable, disable, or change the level of logs, call the
UpdateDeviceState
endpoint. The following sections give examples for each of these cases.
Enabling logs
Specify a log level of 1 (error), 2 (warning), 3 (info), or 4 (debug) in
the desired... control... logLvl field:
{
"desired": {
"control": {
"logLvl": 2
}
}
}
Disabling logs
Specify the log level 0 in the desired... control... logLvl field:
{
"desired": {
"control": {
"logLvl": 0
}
}
}
Changing the log level
Specify the desired log level in the desired... control... logLvl field:
{
"desired": {
"control": {
"logLvl": 3
}
}
}
See the overview for available log levels.
Retrieving logs through the API
To retrieve JSON-based device logs, call the
ListMessages endpoint.
To view only messages related to device logs, include the query parameter
appId=LOG.
Messages in the response might not be in chronological order.
See the endpoint reference for more information on optional filters. See also Device messages.
The following example response includes appId: "LOG":
"items": [
{
"topic": "<environment>/7c57d43f-4307-4d8a-86fe-a14294f1ce93/m/d/nrf-350457790035043/d2c",
"deviceId": "nrf-350423790035043",
"receivedAt": "2023-05-09T11:36:30.501Z",
"message": {
"appId": "LOG",
"dom": 0,
"lvl": 3,
"src": "application",
"ts": 1683632190501,
"seq": 217,
"msg": "Temperature is 23 degrees C"
},
"tenantId": "7c57d43f-4307-4d8a-86fe-a14294f1ce93"
},
]
Downloading binary logs through the API
Use the
FetchBinaryLogsUrl
endpoint to download binary logs for a given device.
Specify the start and end query parameters to select a time range.
Logs are stored for 30 days. The specified start must be in the past 30 days,
and the end can be up to 24 hours after start. If you select an invalid time
range, the server rejects the request.
If you do not choose a time range, the server returns the last 24 hours of logs.
The server responds with a link to a downloadable file. To view the log contents, you must parse the file.