dlog
Logging framework
Loading...
Searching...
No Matches
Dlog

The Dlog API provides functions for sending log output. More...

Enumerations

enum  dlog_error_e {
  DLOG_ERROR_NONE = TIZEN_ERROR_NONE ,
  DLOG_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER ,
  DLOG_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED
}
 Enumeration for Dlog Errors, returned by API calls. More...
enum  log_priority {
  DLOG_VERBOSE ,
  DLOG_DEBUG ,
  DLOG_INFO ,
  DLOG_WARN ,
  DLOG_ERROR ,
  DLOG_FATAL ,
  DLOG_SILENT
}
 Enumeration for log priority values in ascending priority order. More...

Functions

int dlog_print (log_priority prio, const char *tag, const char *fmt,...) __attribute__((format(printf
 Sends a log message with given priority and tag, using printf formatting.
int 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.

Detailed Description

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

PriorityDescription
DLOG_VERBOSEVerbose, 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_DEBUGDebug, meant for tracking execution details during development. Usually gets compiled out for non-debug builds.
DLOG_INFOInfo, for when something remarkable happens during normal operation.
DLOG_WARNWarning, 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_ERRORError, 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_FATALFatal, when an error is hard enough not to be recoverable. Depending on system configuration, dlog can automatically kill the program.
DLOG_SILENTSilent, 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:

NAMESPECIFICATIONEXAMPLE
briefPRI/TAG(PID): MSGE/TEST_APP(123): FOO
processPRI(PID) MSG (TAG)E(123) FOO (TEST_APP)
tagPRI/TAG: MSGE/TEST_APP: FOO
threadPRI('P'PID, 'T'TID) MSGE(P123, T456) FOO
rawMSGFOO
timeREALTIME PRI/TAG(PID): MSG12-31 23:59:59.999 +0200 E/TEST_APP(123): FOO
threadtimeREALTIME PRI/TAG('P'PID, 'T'TID): MSG12-31 23:59:59.999 +0200 E/TEST_APP(P123, T456): FOO
kerneltimeBOOTTIME PRI/TAG('P'PID, 'T'TID): MSG0.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

Enumeration Type Documentation

◆ dlog_error_e

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

Enumerator
DLOG_ERROR_NONE 

Successful

DLOG_ERROR_INVALID_PARAMETER 

Invalid parameter

DLOG_ERROR_NOT_PERMITTED 

Operation not permitted

◆ log_priority

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_tizen 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

◆ dlog_print()

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

Produces a log and sends it to be stored on the DLog backend for later retrieval via dlogutil CLI tool. @since_tizen 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;
}
This file is the header file of the interface of Dlog.
int dlog_print(log_priority prio, const char *tag, const char *fmt,...) __attribute__((format(printf
Sends a log message with given priority and tag, using printf formatting.
@ DLOG_INFO
Definition dlog.h:102

◆ dlog_vprint()

int int dlog_vprint ( log_priority prio,
const char * tag,
const char * fmt,
va_list ap )

Produces a log and sends it to be stored on the DLog backend for later retrieval via dlogutil CLI tool. @since_tizen 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;
}
int 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.