blob: 1bc1f724160090b02134fdf86e5df0572080f2b7 [file] [log] [blame]
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -08001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LOGPRINT_H
18#define _LOGPRINT_H
19
Colin Cross9227bd32013-07-23 16:59:20 -070020#include <log/log.h>
21#include <log/logger.h>
22#include <log/event_tag_map.h>
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080023#include <pthread.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29typedef enum {
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -070030 /* Verbs */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080031 FORMAT_OFF = 0,
32 FORMAT_BRIEF,
33 FORMAT_PROCESS,
34 FORMAT_TAG,
35 FORMAT_THREAD,
36 FORMAT_RAW,
37 FORMAT_TIME,
38 FORMAT_THREADTIME,
39 FORMAT_LONG,
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -070040 /* Adverbs. The following are modifiers to above format verbs */
Mark Salyzyne1f20042015-05-06 08:40:40 -070041 FORMAT_MODIFIER_COLOR, /* converts priority to color */
42 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
Mark Salyzynb932b2f2015-05-15 09:01:58 -070043 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
Mark Salyzynf28f6a92015-08-31 08:01:33 -070044 FORMAT_MODIFIER_YEAR, /* Adds year to date */
45 FORMAT_MODIFIER_ZONE, /* Adds zone to date */
Mark Salyzyn4cbed022015-08-31 15:53:41 -070046 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
47 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
Mark Salyzyn90e7af32015-12-07 16:52:42 -080048 FORMAT_MODIFIER_UID, /* Adds uid */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080049} AndroidLogPrintFormat;
50
51typedef struct AndroidLogFormat_t AndroidLogFormat;
52
53typedef struct AndroidLogEntry_t {
54 time_t tv_sec;
55 long tv_nsec;
56 android_LogPriority priority;
Mark Salyzyn90e7af32015-12-07 16:52:42 -080057 int32_t uid;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080058 int32_t pid;
59 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080060 const char * tag;
61 size_t messageLen;
62 const char * message;
63} AndroidLogEntry;
64
65AndroidLogFormat *android_log_format_new();
66
67void android_log_format_free(AndroidLogFormat *p_format);
68
Mark Salyzyne1f20042015-05-06 08:40:40 -070069/* currently returns 0 if format is a modifier, 1 if not */
70int android_log_setPrintFormat(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080071 AndroidLogPrintFormat format);
72
73/**
74 * Returns FORMAT_OFF on invalid string
75 */
76AndroidLogPrintFormat android_log_formatFromString(const char *s);
77
Mark Salyzyne1f20042015-05-06 08:40:40 -070078/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080079 * filterExpression: a single filter expression
80 * eg "AT:d"
81 *
82 * returns 0 on success and -1 on invalid expression
83 *
84 * Assumes single threaded execution
85 *
86 */
87
Mark Salyzyne1f20042015-05-06 08:40:40 -070088int android_log_addFilterRule(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080089 const char *filterExpression);
90
91
Mark Salyzyne1f20042015-05-06 08:40:40 -070092/**
93 * filterString: a whitespace-separated set of filter expressions
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080094 * eg "AT:d *:i"
95 *
96 * returns 0 on success and -1 on invalid expression
97 *
98 * Assumes single threaded execution
99 *
100 */
101
102int android_log_addFilterString(AndroidLogFormat *p_format,
103 const char *filterString);
104
105
Mark Salyzyne1f20042015-05-06 08:40:40 -0700106/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800107 * returns 1 if this log line should be printed based on its priority
108 * and tag, and 0 if it should not
109 */
110int android_log_shouldPrintLine (
111 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
112
113
114/**
115 * Splits a wire-format buffer into an AndroidLogEntry
116 * entry allocated by caller. Pointers will point directly into buf
117 *
118 * Returns 0 on success and -1 on invalid wire format (entry will be
119 * in unspecified state)
120 */
121int android_log_processLogBuffer(struct logger_entry *buf,
122 AndroidLogEntry *entry);
123
124/**
125 * Like android_log_processLogBuffer, but for binary logs.
126 *
127 * If "map" is non-NULL, it will be used to convert the log tag number
128 * into a string.
129 */
130int android_log_processBinaryLogBuffer(struct logger_entry *buf,
131 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
132 int messageBufLen);
133
134
135/**
136 * Formats a log message into a buffer
137 *
138 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
139 * If return value != defaultBuffer, caller must call free()
140 * Returns NULL on malloc error
141 */
142
Mark Salyzyne1f20042015-05-06 08:40:40 -0700143char *android_log_formatLogLine (
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800144 AndroidLogFormat *p_format,
145 char *defaultBuffer,
146 size_t defaultBufferSize,
147 const AndroidLogEntry *p_line,
148 size_t *p_outLength);
149
150
151/**
152 * Either print or do not print log line, based on filter
153 *
154 * Assumes single threaded execution
155 *
156 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800157int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800158 AndroidLogFormat *p_format,
159 int fd,
160 const AndroidLogEntry *entry);
161
162
163#ifdef __cplusplus
164}
165#endif
166
167
168#endif /*_LOGPRINT_H*/