Tizen Native API  6.5

The Dlog API provides functions for sending log output.

Required Header

#include <dlog.h>

Overview

Sending log message to circular buffer. Dlog APIs include Priority and Tag. By using priority and Tag, we can easily filtered messages what we want to see.

priority

priority level indicates the urgency of log message

Priority Description
DLOG_DEBUG Debug message. - Log message which developer want to check.
DLOG_INFO Information message - Normal operational messages. above of this priority will always be logged.
DLOG_WARN Warning messages - Not an error, but indication that an error will occur if action is not taken.
DLOG_ERROR Error message - Indicate error.

Macro example for useful usage

The Dlog APIs can be used by defining own macros. The macros can be defined like below examples. Thus, developers can use appropriate method as a matter of convenience.

#undef LOG_TAG
#define LOG_TAG "APP_TAG"

#define LOGI(fmt, arg...) \
    ({ do { \
        dlog_print(DLOG_INFO, LOG_TAG, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
    } while (0); })
#define LOGW(fmt, arg...) \
    ({ do { \
        dlog_print(DLOG_WARN, LOG_TAG, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
    } while (0); })
#define LOGE(fmt, arg...) \
    ({ do { \
        dlog_print(DLOG_ERROR, LOG_TAG, "%s: %s(%d) > " fmt, __MODULE__, __func__, __LINE__, ##arg); \
    } while (0); })

Signal

For technical reasons, libdlog blocks the SIGPIPE signal on initialization. If you need to receive it, feel free to reenable it, but note that you may receive the SIGPIPE signal spuriously when writing logs.

dlogutil CLI

dlogutil is a utility that can be utilized to read stored logs.

The most rudimentary way to use it is to run it with no parameters; it then prints all stored logs to the standard output and awaits more.

Parameters exist to change behaviour:

PARAM DESCRIPTION
-s Set default filter to *:s (see later for details)
-f filename Output to given file instead of stdout
-r kbytes Rotate log file every this many kilobytes.
-n files Keep this many old rotations
-v Set log output format.
-b buffer Select another buffer
-c Clear the selected buffers
-d Exit when no more logs are currently available
-t count Similar to -d, except only print this many logs from the end
-g Get the size of selected buffers instead of printing logs
-h, --help Show help info

Additionally, you can specify filters. Filters go behind the parameters and are used to decide which logs are shown.
Each log line has priority and a tag. Filters are specified in the format TAG[:PRIO]. Only logs with given tags and priorities are shown.
You can specify * as the tag to match anything. Beware: only a single asterisk works that way, asterisk is not otherwise expanded. For example, "T*G" filter will NOT match "TAG", only literal "T*G".
If you don't specify any filter, it defaults to *:I
If you specify just * as the tag, without priority, its priority defaults to D
If you specify any other tag without priority, the priority defaults to V

dlogutil allows you to specify buffers. These are:

NAMEREMARKS
mainthe default, for general platform logging
systemfor system logs
radiofor radio logs
appsfor applications
kmsga copy of kernel messages (dmesg)

There are also priorities to be specified. These are one letter abbreviations of the following levels:

LEVELDESCRIPTION
V verbose
D debug
I info
W warning
E error
F fatal
S silent

Depending on products, some of priorities (e.g., V and D) can be disabled by default to prevent too many logs.

Formats, and what they look like:

NAME SPECIFICATION EXAMPLE
brief PRI/TAG(PID): MSG E/TEST_APP(123): FOO
process PRI(PID) MSG (TAG) E(123) FOO (TEST_APP)
tag PRI/TAG: MSG E/TEST_APP: FOO
thread PRI('P'PID, 'T'TID) MSG E(P123, T456) FOO
raw MSG FOO
time REALTIME PRI/TAG(PID): MSG 12-31 23:59:59.999 +0200 E/TEST_APP(123): FOO
threadtimeREALTIME PRI/TAG('P'PID, 'T'TID): MSG 12-31 23:59:59.999 +0200 E/TEST_APP(P123, T456): FOO
kerneltimeBOOTTIME PRI/TAG('P'PID, 'T'TID): MSG 0.123 E/TEST_APP(P123, T456): FOO
long [REALTIME PRI/TAG 'P'PID, 'T'TID]
MSG
[12-31 23:59:59.999 +0200 E/TEST_APP P123, T456]
FOO

Functions

int dlog_print (log_priority prio, const char *tag, const char *fmt,...)
 Sends log with priority and tag.
int dlog_vprint (log_priority prio, const char *tag, const char *fmt, va_list ap)
 Sends log with priority, tag, and va_list.

Enumeration Type Documentation

Enumeration for Dlog Error.

Since :
2.3
Enumerator:
DLOG_ERROR_NONE 

Successful

DLOG_ERROR_INVALID_PARAMETER 

Invalid parameter

DLOG_ERROR_NOT_PERMITTED 

Operation not permitted

Enumeration for log priority values in ascending priority order.

Since :
2.3
Enumerator:
DLOG_UNKNOWN 

Keep this always at the start

DLOG_DEFAULT 

Default

DLOG_VERBOSE 

Verbose

DLOG_DEBUG 

Debug

DLOG_INFO 

Info

DLOG_WARN 

Warning

DLOG_ERROR 

Error

DLOG_FATAL 

Fatal

DLOG_SILENT 

Silent

DLOG_PRIO_MAX 

Keep this always at the end.


Function Documentation

int dlog_print ( log_priority  prio,
const char *  tag,
const char *  fmt,
  ... 
)

Sends log with priority and tag.

for application.

Since :
2.3
Parameters:
[in]priopriority level of type log_priority
[in]tagtag - a null-terminated string
[in]fmtformat string - same as printf
Returns:
On success, the function returns the number of bytes written. On error, a negative errno-style error code
Return values:
DLOG_ERROR_INVALID_PARAMETERInvalid parameter
DLOG_ERROR_NOT_PERMITTEDOperation not permitted
Precondition:
none
Postcondition:
none
See also:
dlog_vprint
#include<dlog.h>
int main(void)
{
    int integer = 21;
    char string[] = "test dlog";

    dlog_print(DLOG_INFO, "USR_TAG", "test dlog");
    dlog_print(DLOG_INFO, "USR_TAG", "%s, %d", string, integer);
    return 0;
}
int dlog_vprint ( log_priority  prio,
const char *  tag,
const char *  fmt,
va_list  ap 
)

Sends log with priority, tag, and va_list.

for application.

Since :
2.3
Parameters:
[in]priopriority level of type log_priority
[in]tagtag - a null-terminated string
[in]fmtformat string - same as printf
[in]apva_list
Returns:
On success, the function returns the number of bytes written. On error, a negative errno-style error code
Return values:
DLOG_ERROR_INVALID_PARAMETERInvalid parameter
DLOG_ERROR_NOT_PERMITTEDOperation not permitted
Precondition:
none
Postcondition:
none
See also:
dlog_print
#include<dlog.h>
void my_debug_print(char *format, ...)
{
    va_list ap;

    va_start(ap, format);
    dlog_vprint(DLOG_INFO, "USR_TAG", format, ap);
    va_end(ap);
}

int main(void)
{
    my_debug_print("%s", "test dlog");
    my_debug_print("%s, %d", "test dlog", 21);
    return 0;
}