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.
- Key Name:
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.
- Key Name:
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
keepDaysnumber of days will not be deleted. If not specified, all archives will be deleted.
- Key Name:
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.
- Kotlin
- Java
- ADB
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)
}
void logDemo()
{
String logPackage = "com.datalogic.logger";
// Create/Send intent to start a log session.
Intent startLog = new Intent("com.datalogic.logger.START_LOG");
startLog.setPackage(logPackage);
sendBroadcast(startLog);
// Create/Send intent to stop a log session.
Intent stopLog = new Intent("com.datalogic.logger.STOP_LOG");
stopLog.setPackage(logPackage);
sendBroadcast(stopLog);
// Create/Send intent to export the latest archive to a specific URL.
Intent exportLog = new Intent("com.datalogic.logger.EXPORT_LOG");
String 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.
Intent exportAll = Intent("com.datalogic.logger.EXPORT_ALL_LOGS");
string 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.
Intent deleteAll = Intent("com.datalogic.logger.DELETE_ALL_LOGS")
int keepDays = 5;
deleteAll.setPackage(logPackage);
deleteAll.putExtra("keepDays", keepDays);
sendBroadcast(deleteAll);
}
Start logging:
adb shell am broadcast -a com.datalogic.logger.START_LOG com.datalogic.logger
Stop logging:
adb shell am broadcast -a com.datalogic.logger.STOP_LOG com.datalogic.logger
Export latest archive to URL:
adb shell am broadcast -a com.datalogic.logger.EXPORT_LOG --es url "https://www.myserver.com/logUploads" com.datalogic.logger
Export all archives to URL:
adb shell am broadcast -a com.datalogic.logger.EXPORT_ALL_LOGS --es url "https://www.myserver.com/logUploads" com.datalogic.logger
Delete all archives older than 5 days:
adb shell am broadcast -a com.datalogic.logger.DELETE_ALL_LOGS --ei keepDays 5 com.datalogic.logger