blob: 26b1ee5a15dfb136f5ea743b4a0ac289972e44a2 [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 */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080045} AndroidLogPrintFormat;
46
47typedef struct AndroidLogFormat_t AndroidLogFormat;
48
49typedef struct AndroidLogEntry_t {
50 time_t tv_sec;
51 long tv_nsec;
52 android_LogPriority priority;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080053 int32_t pid;
54 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080055 const char * tag;
56 size_t messageLen;
57 const char * message;
58} AndroidLogEntry;
59
60AndroidLogFormat *android_log_format_new();
61
62void android_log_format_free(AndroidLogFormat *p_format);
63
Mark Salyzyne1f20042015-05-06 08:40:40 -070064/* currently returns 0 if format is a modifier, 1 if not */
65int android_log_setPrintFormat(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080066 AndroidLogPrintFormat format);
67
68/**
69 * Returns FORMAT_OFF on invalid string
70 */
71AndroidLogPrintFormat android_log_formatFromString(const char *s);
72
Mark Salyzyne1f20042015-05-06 08:40:40 -070073/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080074 * filterExpression: a single filter expression
75 * eg "AT:d"
76 *
77 * returns 0 on success and -1 on invalid expression
78 *
79 * Assumes single threaded execution
80 *
81 */
82
Mark Salyzyne1f20042015-05-06 08:40:40 -070083int android_log_addFilterRule(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080084 const char *filterExpression);
85
86
Mark Salyzyne1f20042015-05-06 08:40:40 -070087/**
88 * filterString: a whitespace-separated set of filter expressions
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080089 * eg "AT:d *:i"
90 *
91 * returns 0 on success and -1 on invalid expression
92 *
93 * Assumes single threaded execution
94 *
95 */
96
97int android_log_addFilterString(AndroidLogFormat *p_format,
98 const char *filterString);
99
100
Mark Salyzyne1f20042015-05-06 08:40:40 -0700101/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800102 * returns 1 if this log line should be printed based on its priority
103 * and tag, and 0 if it should not
104 */
105int android_log_shouldPrintLine (
106 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
107
108
109/**
110 * Splits a wire-format buffer into an AndroidLogEntry
111 * entry allocated by caller. Pointers will point directly into buf
112 *
113 * Returns 0 on success and -1 on invalid wire format (entry will be
114 * in unspecified state)
115 */
116int android_log_processLogBuffer(struct logger_entry *buf,
117 AndroidLogEntry *entry);
118
119/**
120 * Like android_log_processLogBuffer, but for binary logs.
121 *
122 * If "map" is non-NULL, it will be used to convert the log tag number
123 * into a string.
124 */
125int android_log_processBinaryLogBuffer(struct logger_entry *buf,
126 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
127 int messageBufLen);
128
129
130/**
131 * Formats a log message into a buffer
132 *
133 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
134 * If return value != defaultBuffer, caller must call free()
135 * Returns NULL on malloc error
136 */
137
Mark Salyzyne1f20042015-05-06 08:40:40 -0700138char *android_log_formatLogLine (
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800139 AndroidLogFormat *p_format,
140 char *defaultBuffer,
141 size_t defaultBufferSize,
142 const AndroidLogEntry *p_line,
143 size_t *p_outLength);
144
145
146/**
147 * Either print or do not print log line, based on filter
148 *
149 * Assumes single threaded execution
150 *
151 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800152int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800153 AndroidLogFormat *p_format,
154 int fd,
155 const AndroidLogEntry *entry);
156
157
158#ifdef __cplusplus
159}
160#endif
161
162
163#endif /*_LOGPRINT_H*/