dlog: Sending Log Output for Debug Activities
This tutorial demonstrates how you can send log messages to a circular log device and check them.
Warm-up
Become familiar with the dlog API basics by learning about:
-
Initializing dlog
Initialize dlog for use.
-
Sending a Log Message
Send a log message.
-
Checking the Output Logs
Check the output.
Initializing dlog
To initialize dlog:
-
To use the functions and data types of the dlog API (in mobile and wearable applications), include the <dlog.h> header file in your application:
#include <dlog.h>
- Make sure you have the necessary tools:
- dlog library: libdlog.so
The dlog library provides a logging function to send log messages to the kernel log device.
- dlogutil: dlogutil
dlogutil enables you to view log messages in the log device, and provides filtered message output.
- Requirement: linux-2.6.32 kernel
- dlog library: libdlog.so
Sending a Log Message
Send a log message with the MY_APP tag with various priorities.
#include<dlog.h> #define TAG "MY_APP" int main(void) { int integer = 21; char string[] = "test dlog"; dlog_print(DLOG_DEBUG, TAG, "debug message"); dlog_print(DLOG_INFO, TAG, "info message"); dlog_print(DLOG_WARN, TAG, "warning message"); dlog_print(DLOG_ERROR, TAG, "error message"); dlog_print(DLOG_INFO, TAG, "%s, %d", string, integer); return 0; }
Checking the Output Logs
Execute dlogutil on the device sdb shell to check the out log.
Check the sdb guide to connect to a target and use it.
Desktop:~$ sdb shell sh-3.2# sh-3.2# dlogutil MY_APP arc = 2, optind = 1, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main D/MY_APP (11097): debug message I/MY_APP (11097): info message W/MY_APP (11097): warning message E/MY_APP (11097): error message I/MY_APP (11097): test dlog, 21 sh-3.2# dlogutil MY_APP:I arc = 2, optind = 1, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main I/MY_APP (11097): info message W/MY_APP (11097): warning message E/MY_APP (11097): error message I/MY_APP (11097): test dlog, 21 sh-3.2# dlogutil MY_APP:W arc = 2, optind = 1, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main W/MY_APP (11097): warning message E/MY_APP (11097): error message sh-3.2# dlogutil MY_APP:E arc = 2, optind = 1, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main E/MY_APP (11097): error message sh-3.2# dlogutil -v time MY_APP arc = 4, optind = 3, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main 12-26 07:06:02.084+0000 D/MY_APP (11097): debug message 12-26 07:06:02.084+0000 I/MY_APP (11097): info message 12-26 07:06:02.084+0000 W/MY_APP (11097): warning message 12-26 07:06:02.084+0000 E/MY_APP (11097): error message 12-26 07:06:02.084+0000 I/MY_APP (11097): test dlog, 21 sh-3.2# dlogutil -v threadtime MY_APP arc = 4, optind = 3, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main 12-26 07:06:02.084+0000 11097 11097 D MY_APP : debug message 12-26 07:06:02.084+0000 11097 11097 I MY_APP : info message 12-26 07:06:02.084+0000 11097 11097 W MY_APP : warning message 12-26 07:06:02.084+0000 11097 11097 E MY_APP : error message 12-26 07:06:02.084+0000 11097 11097 I MY_APP : test dlog, 21 sh-3.2# dlogutil -v long MY_APP arc = 4, optind = 3, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main [ 12-26 07:06:02.084 11097:11097 D/MY_APP ] debug message [ 12-26 07:06:02.084 11097:11097 I/MY_APP ] info message [ 12-26 07:06:02.084 11097:11097 W/MY_APP ] warning message [ 12-26 07:06:02.084 11097:11097 E/MY_APP ] error message [ 12-26 07:06:02.084 11097:11097 I/MY_APP ] test dlog, 21 sh-3.2# dlogutil -v raw MY_APP arc = 4, optind = 3, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main debug message info message warning message error message test dlog, 21 sh-3.2# dlogutil -v brief MY_APP arc = 4, optind = 3, Kb 0, rotate 4 --------- beginning of /dev/log_system --------- beginning of /dev/log_main D/MY_APP (11097): debug message I/MY_APP (11097): info message W/MY_APP (11097): warning message E/MY_APP (11097): error message I/MY_APP (11097): test dlog, 21