Skip to main content

Logger API

Command Intents​

Applications can send commands to Datalogic Logger through a set of API intents. These intents perform the same actions that are available through the Logger application. They can be useful to issues commands in response to a system event, such as the start of a user login, or the reporting of an error.

To avoid the potential for any application other than Datalogic Logger from processing the Intent, all intents should be created using the following package name for the recipient:

com.datalogic.logger

The available intents with specific details on their behavior are listed below.

Start a Log Session​

  • Intent Action: com.datalogic.logger.START_LOG
  • Intent Data: None
  • Intent Extra Data: None

A new log session is started using the existing configuration settings. If the logging service is busy (already running), this command will be ignored.

If this command is issued early during a device reboot, any unsaved log content from a previous session (due to a system crash) will be archived before starting a new session.

Stop a Log Session​

  • Intent Action: com.datalogic.logger.STOP_LOG
  • Intent Data: None
  • Intent Extra Data: None

Any current log session is stopped, and an archive file of the log content will be created. If no log session was currently active, this command will be ignored.

Export Latest Log Archive​

  • Intent Action: com.datalogic.logger.EXPORT_LOG
  • Intent Data: None
  • Intent Extra Data: Optional
    • Key Name: url
    • Type: String
    • Description: If included, this specifies the server URL to use for exporting the archive. If not included, the existing configuration setting will be used.

The most recent archive on the device will be exported to the server URL specified by the current configuration setting (or the URL specified by the optional extra data in the intent). Any archive that is already queued for export will not be considered in selecting the most recent archive. If no archive exists, this command will be ignored.

If this command is issued early during a device reboot, any unsaved log content from a previous session (due to a system crash) will be archived and then selected to be exported.

Export All Log Archives​

  • Intent Action: com.datalogic.logger.EXPORT_ALL_LOGS
  • Intent Data: None
  • Intent Extra Data: Optional
    • Key Name: url
    • Type: String
    • Description: If included, this specifies the server URL to use for exporting the archive. If not included, the existing configuration setting will be used.

All archives on the device will be exported to the server URL specified by the current configuration setting (or the URL specified by the optional extra data in the intent). If no archive exists, this command will be ignored.

If this command is issued early during a device reboot, any unsaved log content from a previous session (due to a system crash) will be archived and then selected to be exported.

Delete All Log Archives​

  • Intent Action: com.datalogic.logger.DELETE_ALL_LOGS
  • Intent Data: None
  • Intent Extra Data: Optional
    • Key Name: keepDays
    • Type: Int
    • Description: If included, any archive which was created within the last keepDays number of days will not be deleted. If not specified, all archives will be deleted.

All (qualified) archives on the device will be deleted. This can be used to remove old archives which were never exported (and thus removed). If log archives are generated on a regular basis, this can be issued (with the keepDays extra) to keep the archive storage from becoming too large. Any archives which have already been marked for export will not be deleted.

Sample code​

The following code fragment illustrates how to issue each of the logger intents from an activity.

fun logDemo()
{
val logPackage = "com.datalogic.logger"

// Create/Send intent to start a log session.
val startLog = Intent("com.datalogic.logger.START_LOG")
startLog.setPackage(logPackage)
sendBroadcast(startLog)

// Create/Send intent to stop a log session.
val stopLog = Intent("com.datalogic.logger.STOP_LOG")
stopLog.setPackage(logPackage)
sendBroadcast(stopLog)

// Create/Send intent to export the latest archive to a specific URL.
val exportLog = Intent("com.datalogic.logger.EXPORT_LOG")
val serverUrl = "https://www.myserver.com/logUploads"
exportLog.setPackage(logPackage)
exportLog.putExtra("url", serverUrl)
sendBroadcast(exportLog)

// Create/Send intent to export all archives to a specific URL.
val exportAll = Intent("com.datalogic.logger.EXPORT_ALL_LOGS")
val serverUrl2 = "https://www.myserver.com/logUploads"
exportAll.setPackage(logPackage)
exportAll.putExtra("url", serverUrl2)
sendBroadcast(exportAll)

// Create/Send intent to delete all archives older than 5 days.
val deleteAll = Intent("com.datalogic.logger.DELETE_ALL_LOGS")
val keepDays = 5
deleteAll.setPackage(logPackage)
deleteAll.putExtra("keepDays", keepDays)
sendBroadcast(deleteAll)
}