Tizen Native API  10.0

The Dlog API provides functions for sending log output.

DLog is the default logging interface for Tizen. The core interface is just `dlog_print`, which is completely standalone and has essentially no preconditions. Logs can later be retrieved using the `dlogutil` CLI tool or `libdlogutil` library.

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_VERBOSE Verbose, use to let users track what's going on with extra detail. Usually you'll want to gate this behind a `--verbose` flag or similar.
DLOG_DEBUG Debug, meant for tracking execution details during development. Usually gets compiled out for non-debug builds.
DLOG_INFO Info, for when something remarkable happens during normal operation.
DLOG_WARN Warning, for suspicious activity or something that may warrant attention that isn't yet an error. Most tools' default filtering passes this level and above through.
DLOG_ERROR Error, use when something fails. Avoid using this level as a generic "high priority" message because errors look scary to everybody else; on the other hand if you're writing a tool that parses logs remember that this is how it often gets used in practice.
DLOG_FATAL Fatal, when an error is hard enough not to be recoverable. Depending on system configuration, dlog can automatically kill the program.
DLOG_SILENT Silent, for use in filtering tools to "silence" logs, by being higher than the highest "real" level.

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 a log message with given priority and tag, using printf formatting.
int dlog_vprint (log_priority prio, const char *tag, const char *fmt, va_list ap)
 Sends a log message with given priority and tag label, using variadic args.

Enumeration Type Documentation

Enumeration for Dlog Errors, returned by API calls.

Some of DLog API calls can return these to denote what happened.

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.

Priority level controls how important a message is. This is both a way to a developer to gauge it and for tools to filter for it.

Since :
2.3
Enumerator:
DLOG_VERBOSE 

Verbose, use to let users track what's going on with extra detail. Usually you'll want to gate this behind a `--verbose` flag or similar.

DLOG_DEBUG 

Debug, meant for tracking execution details during development. Usually gets compiled out for non-debug builds.

DLOG_INFO 

Info, for when something remarkable happens during normal operation.

DLOG_WARN 

Warning, for suspicious activity or something that may warrant attention that isn't yet an error. Default filtering passes this level and above through.

DLOG_ERROR 

Error, use when something fails.

DLOG_FATAL 

Fatal, when an error is hard enough not to be recoverable. Depending on system configuration, dlog can automatically kill the program.

DLOG_SILENT 

Silent, for use in filtering tools to "silence" logs, by being higher than the highest "real" level.


Function Documentation

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

Sends a log message with given priority and tag, using printf formatting.

Produces a log and sends it to be stored on the DLog backend for later retrieval via dlogutil CLI tool.

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 a log message with given priority and tag label, using variadic args.

Produces a log and sends it to be stored on the DLog backend for later retrieval via dlogutil CLI tool.

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;
}