blob: b8d8d4ccbae65c0b5050f3e4138f34dcc5cdd346 [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
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080020#include <pthread.h>
21
Mark Salyzynff2dcd92016-09-28 15:54:45 -070022#include <android/log.h>
23#include <log/event_tag_map.h>
24#include <log/logger.h>
25
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080026#ifdef __cplusplus
27extern "C" {
28#endif
29
30typedef enum {
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -070031 /* Verbs */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080032 FORMAT_OFF = 0,
33 FORMAT_BRIEF,
34 FORMAT_PROCESS,
35 FORMAT_TAG,
36 FORMAT_THREAD,
37 FORMAT_RAW,
38 FORMAT_TIME,
39 FORMAT_THREADTIME,
40 FORMAT_LONG,
Mark Salyzyn9cfd1c62016-07-06 11:12:14 -070041 /* Adverbs. The following are modifiers to above format verbs */
Mark Salyzyne1f20042015-05-06 08:40:40 -070042 FORMAT_MODIFIER_COLOR, /* converts priority to color */
43 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
Mark Salyzynb932b2f2015-05-15 09:01:58 -070044 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
Mark Salyzynf28f6a92015-08-31 08:01:33 -070045 FORMAT_MODIFIER_YEAR, /* Adds year to date */
46 FORMAT_MODIFIER_ZONE, /* Adds zone to date */
Mark Salyzyn4cbed022015-08-31 15:53:41 -070047 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
48 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
Mark Salyzyn90e7af32015-12-07 16:52:42 -080049 FORMAT_MODIFIER_UID, /* Adds uid */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050} AndroidLogPrintFormat;
51
52typedef struct AndroidLogFormat_t AndroidLogFormat;
53
54typedef struct AndroidLogEntry_t {
55 time_t tv_sec;
56 long tv_nsec;
57 android_LogPriority priority;
Mark Salyzyn90e7af32015-12-07 16:52:42 -080058 int32_t uid;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080059 int32_t pid;
60 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080061 const char * tag;
62 size_t messageLen;
63 const char * message;
64} AndroidLogEntry;
65
66AndroidLogFormat *android_log_format_new();
67
68void android_log_format_free(AndroidLogFormat *p_format);
69
Mark Salyzyne1f20042015-05-06 08:40:40 -070070/* currently returns 0 if format is a modifier, 1 if not */
71int android_log_setPrintFormat(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080072 AndroidLogPrintFormat format);
73
74/**
75 * Returns FORMAT_OFF on invalid string
76 */
77AndroidLogPrintFormat android_log_formatFromString(const char *s);
78
Mark Salyzyne1f20042015-05-06 08:40:40 -070079/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080080 * filterExpression: a single filter expression
81 * eg "AT:d"
82 *
83 * returns 0 on success and -1 on invalid expression
84 *
85 * Assumes single threaded execution
86 *
87 */
88
Mark Salyzyne1f20042015-05-06 08:40:40 -070089int android_log_addFilterRule(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080090 const char *filterExpression);
91
92
Mark Salyzyne1f20042015-05-06 08:40:40 -070093/**
94 * filterString: a whitespace-separated set of filter expressions
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080095 * eg "AT:d *:i"
96 *
97 * returns 0 on success and -1 on invalid expression
98 *
99 * Assumes single threaded execution
100 *
101 */
102
103int android_log_addFilterString(AndroidLogFormat *p_format,
104 const char *filterString);
105
106
Mark Salyzyne1f20042015-05-06 08:40:40 -0700107/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800108 * returns 1 if this log line should be printed based on its priority
109 * and tag, and 0 if it should not
110 */
111int android_log_shouldPrintLine (
112 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
113
114
115/**
116 * Splits a wire-format buffer into an AndroidLogEntry
117 * entry allocated by caller. Pointers will point directly into buf
118 *
119 * Returns 0 on success and -1 on invalid wire format (entry will be
120 * in unspecified state)
121 */
122int android_log_processLogBuffer(struct logger_entry *buf,
123 AndroidLogEntry *entry);
124
125/**
126 * Like android_log_processLogBuffer, but for binary logs.
127 *
128 * If "map" is non-NULL, it will be used to convert the log tag number
129 * into a string.
130 */
131int android_log_processBinaryLogBuffer(struct logger_entry *buf,
132 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
133 int messageBufLen);
134
135
136/**
137 * Formats a log message into a buffer
138 *
139 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
140 * If return value != defaultBuffer, caller must call free()
141 * Returns NULL on malloc error
142 */
143
Mark Salyzyne1f20042015-05-06 08:40:40 -0700144char *android_log_formatLogLine (
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800145 AndroidLogFormat *p_format,
146 char *defaultBuffer,
147 size_t defaultBufferSize,
148 const AndroidLogEntry *p_line,
149 size_t *p_outLength);
150
151
152/**
153 * Either print or do not print log line, based on filter
154 *
155 * Assumes single threaded execution
156 *
157 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800158int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800159 AndroidLogFormat *p_format,
160 int fd,
161 const AndroidLogEntry *entry);
162
163
164#ifdef __cplusplus
165}
166#endif
167
168
169#endif /*_LOGPRINT_H*/