platform_system_core/liblog/README.protocol.md
Tom Cherry a379b1ce05 liblog: document the liblog<->logd protocol format
This protocol documentation is spread out among various functions
where it is implemented.  This change makes a single
README.protocol.md file with a high level overview, referencing the
struct names where useful.

Test: n/a
Change-Id: I83c9f484352b489b4a20cce241d92413f780f9ec
2019-10-24 11:19:06 -07:00

1.7 KiB

liblog -> logd

The data that liblog sends to logd is represented below.

struct {
    android_log_header_t header;
    union {
       struct {
            char     prio;
            char     tag[...];
            char     message[...];
        } string;
        struct {
            android_event_header_t event_header;
            android_event_*_t      payload[...];
        } binary;
    };
};

The payload, excluding the header, has a max size of LOGGER_ENTRY_MAX_PAYLOAD.

header

The header is added immediately before sending the log message to logd.

string payload

The string part of the union is for normal buffers (main, system, radio, etc) and consists of a single character priority, followed by a variable length null terminated string for the tag, and finally a variable length null terminated string for the message.

This payload is used for the __android_log_buf_write() family of functions.

binary payload

The binary part of the union is for binary buffers (events, security, etc) and consists of an android_event_header_t struct followed by a variable number of android_event_*_t (android_event_list_t, android_event_int_t, etc) structs.

If multiple android_event_*_t elements are present, then they must be in a list and the first element in payload must be an android_event_list_t.

This payload is used for the __android_log_bwrite() family of functions. It is additionally used for android_log_write_list() and the related functions that manipulate event lists.

logd -> liblog

logd sends a logger_entry struct to liblog followed by the payload. The payload is identical to the payloads defined above. The max size of the entire message from logd is LOGGER_ENTRY_MAX_LEN.