summaryrefslogtreecommitdiffstats
blob: 3509e7f519c8207116d6b10b9c8ac34ecca53868 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef _LOGPRINT_H
#define _LOGPRINT_H

#include <pthread.h>

#include <android/log.h>
#include <log/event_tag_map.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    /* Verbs */
    FORMAT_OFF = 0,
    FORMAT_BRIEF,
    FORMAT_PROCESS,
    FORMAT_TAG,
    FORMAT_THREAD,
    FORMAT_RAW,
    FORMAT_TIME,
    FORMAT_THREADTIME,
    FORMAT_LONG,
    /* Adverbs. The following are modifiers to above format verbs */
    FORMAT_MODIFIER_COLOR,     /* converts priority to color */
    FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
    FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
    FORMAT_MODIFIER_YEAR,      /* Adds year to date */
    FORMAT_MODIFIER_ZONE,      /* Adds zone to date */
    FORMAT_MODIFIER_EPOCH,     /* Print time as seconds since Jan 1 1970 */
    FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
    FORMAT_MODIFIER_UID,       /* Adds uid */
    FORMAT_MODIFIER_DESCRIPT,  /* Adds descriptive */
} AndroidLogPrintFormat;

typedef struct AndroidLogFormat_t AndroidLogFormat;

typedef struct AndroidLogEntry_t {
    time_t tv_sec;
    long tv_nsec;
    android_LogPriority priority;
    int32_t uid;
    int32_t pid;
    int32_t tid;
    const char* tag;
    size_t tagLen;
    size_t messageLen;
    const char* message;
} AndroidLogEntry;

AndroidLogFormat* android_log_format_new();

void android_log_format_free(AndroidLogFormat* p_format);

/* currently returns 0 if format is a modifier, 1 if not */
int android_log_setPrintFormat(AndroidLogFormat* p_format,
        AndroidLogPrintFormat format);

/**
 * Returns FORMAT_OFF on invalid string
 */
AndroidLogPrintFormat android_log_formatFromString(const char* s);

/**
 * filterExpression: a single filter expression
 * eg "AT:d"
 *
 * returns 0 on success and -1 on invalid expression
 *
 * Assumes single threaded execution
 *
 */

int android_log_addFilterRule(AndroidLogFormat* p_format,
        const char* filterExpression);

/**
 * filterString: a whitespace-separated set of filter expressions
 * eg "AT:d *:i"
 *
 * returns 0 on success and -1 on invalid expression
 *
 * Assumes single threaded execution
 *
 */

int android_log_addFilterString(AndroidLogFormat* p_format,
        const char* filterString);

/**
 * returns 1 if this log line should be printed based on its priority
 * and tag, and 0 if it should not
 */
int android_log_shouldPrintLine (
        AndroidLogFormat* p_format, const char* tag, android_LogPriority pri);

/**
 * Splits a wire-format buffer into an AndroidLogEntry
 * entry allocated by caller. Pointers will point directly into buf
 *
 * Returns 0 on success and -1 on invalid wire format (entry will be
 * in unspecified state)
 */
int android_log_processLogBuffer(struct logger_entry* buf,
                                 AndroidLogEntry* entry);

/**
 * Like android_log_processLogBuffer, but for binary logs.
 *
 * If "map" is non-NULL, it will be used to convert the log tag number
 * into a string.
 */
int android_log_processBinaryLogBuffer(struct logger_entry* buf,
    AndroidLogEntry* entry, const EventTagMap* map, char* messageBuf,
    int messageBufLen);

/**
 * Formats a log message into a buffer
 *
 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
 * If return value != defaultBuffer, caller must call free()
 * Returns NULL on malloc error
 */

char* android_log_formatLogLine (
    AndroidLogFormat* p_format,
    char* defaultBuffer,
    size_t defaultBufferSize,
    const AndroidLogEntry* p_line,
    size_t* p_outLength);

/**
 * Either print or do not print log line, based on filter
 *
 * Assumes single threaded execution
 *
 */
int android_log_printLogLine(
    AndroidLogFormat* p_format,
    int fd,
    const AndroidLogEntry* entry);

#ifdef __cplusplus
}
#endif

#endif /*_LOGPRINT_H*/