blob: 539d1dcff822229e427d8a5d70e8ee20cfddff5c [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 {
30 FORMAT_OFF = 0,
31 FORMAT_BRIEF,
32 FORMAT_PROCESS,
33 FORMAT_TAG,
34 FORMAT_THREAD,
35 FORMAT_RAW,
36 FORMAT_TIME,
37 FORMAT_THREADTIME,
38 FORMAT_LONG,
Mark Salyzynf28f6a92015-08-31 08:01:33 -070039 /* The following are modifiers to above formats */
Mark Salyzyne1f20042015-05-06 08:40:40 -070040 FORMAT_MODIFIER_COLOR, /* converts priority to color */
41 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
Mark Salyzynb932b2f2015-05-15 09:01:58 -070042 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
Mark Salyzynf28f6a92015-08-31 08:01:33 -070043 FORMAT_MODIFIER_YEAR, /* Adds year to date */
44 FORMAT_MODIFIER_ZONE, /* Adds zone to date */
Mark Salyzyn4cbed022015-08-31 15:53:41 -070045 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
46 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
Mark Salyzyn90e7af32015-12-07 16:52:42 -080047 FORMAT_MODIFIER_UID, /* Adds uid */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080048} AndroidLogPrintFormat;
49
50typedef struct AndroidLogFormat_t AndroidLogFormat;
51
52typedef struct AndroidLogEntry_t {
53 time_t tv_sec;
54 long tv_nsec;
55 android_LogPriority priority;
Mark Salyzyn90e7af32015-12-07 16:52:42 -080056 int32_t uid;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080057 int32_t pid;
58 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080059 const char * tag;
60 size_t messageLen;
61 const char * message;
62} AndroidLogEntry;
63
64AndroidLogFormat *android_log_format_new();
65
66void android_log_format_free(AndroidLogFormat *p_format);
67
Mark Salyzyne1f20042015-05-06 08:40:40 -070068/* currently returns 0 if format is a modifier, 1 if not */
69int android_log_setPrintFormat(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080070 AndroidLogPrintFormat format);
71
72/**
73 * Returns FORMAT_OFF on invalid string
74 */
75AndroidLogPrintFormat android_log_formatFromString(const char *s);
76
Mark Salyzyne1f20042015-05-06 08:40:40 -070077/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080078 * filterExpression: a single filter expression
79 * eg "AT:d"
80 *
81 * returns 0 on success and -1 on invalid expression
82 *
83 * Assumes single threaded execution
84 *
85 */
86
Mark Salyzyne1f20042015-05-06 08:40:40 -070087int android_log_addFilterRule(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080088 const char *filterExpression);
89
90
Mark Salyzyne1f20042015-05-06 08:40:40 -070091/**
92 * filterString: a whitespace-separated set of filter expressions
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080093 * eg "AT:d *:i"
94 *
95 * returns 0 on success and -1 on invalid expression
96 *
97 * Assumes single threaded execution
98 *
99 */
100
101int android_log_addFilterString(AndroidLogFormat *p_format,
102 const char *filterString);
103
104
Mark Salyzyne1f20042015-05-06 08:40:40 -0700105/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800106 * returns 1 if this log line should be printed based on its priority
107 * and tag, and 0 if it should not
108 */
109int android_log_shouldPrintLine (
110 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
111
112
113/**
114 * Splits a wire-format buffer into an AndroidLogEntry
115 * entry allocated by caller. Pointers will point directly into buf
116 *
117 * Returns 0 on success and -1 on invalid wire format (entry will be
118 * in unspecified state)
119 */
120int android_log_processLogBuffer(struct logger_entry *buf,
121 AndroidLogEntry *entry);
122
123/**
124 * Like android_log_processLogBuffer, but for binary logs.
125 *
126 * If "map" is non-NULL, it will be used to convert the log tag number
127 * into a string.
128 */
129int android_log_processBinaryLogBuffer(struct logger_entry *buf,
130 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
131 int messageBufLen);
132
133
134/**
135 * Formats a log message into a buffer
136 *
137 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
138 * If return value != defaultBuffer, caller must call free()
139 * Returns NULL on malloc error
140 */
141
Mark Salyzyne1f20042015-05-06 08:40:40 -0700142char *android_log_formatLogLine (
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800143 AndroidLogFormat *p_format,
144 char *defaultBuffer,
145 size_t defaultBufferSize,
146 const AndroidLogEntry *p_line,
147 size_t *p_outLength);
148
149
150/**
151 * Either print or do not print log line, based on filter
152 *
153 * Assumes single threaded execution
154 *
155 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800156int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800157 AndroidLogFormat *p_format,
158 int fd,
159 const AndroidLogEntry *entry);
160
161
162#ifdef __cplusplus
163}
164#endif
165
166
167#endif /*_LOGPRINT_H*/