blob: 96249e98f355cf1e672a1734c28500ad7b867d23 [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 Salyzyne1f20042015-05-06 08:40:40 -070039 /* The following two are modifiers to above formats */
40 FORMAT_MODIFIER_COLOR, /* converts priority to color */
41 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080042} AndroidLogPrintFormat;
43
44typedef struct AndroidLogFormat_t AndroidLogFormat;
45
46typedef struct AndroidLogEntry_t {
47 time_t tv_sec;
48 long tv_nsec;
49 android_LogPriority priority;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080050 int32_t pid;
51 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080052 const char * tag;
53 size_t messageLen;
54 const char * message;
55} AndroidLogEntry;
56
57AndroidLogFormat *android_log_format_new();
58
59void android_log_format_free(AndroidLogFormat *p_format);
60
Mark Salyzyne1f20042015-05-06 08:40:40 -070061/* currently returns 0 if format is a modifier, 1 if not */
62int android_log_setPrintFormat(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080063 AndroidLogPrintFormat format);
64
65/**
66 * Returns FORMAT_OFF on invalid string
67 */
68AndroidLogPrintFormat android_log_formatFromString(const char *s);
69
Mark Salyzyne1f20042015-05-06 08:40:40 -070070/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080071 * filterExpression: a single filter expression
72 * eg "AT:d"
73 *
74 * returns 0 on success and -1 on invalid expression
75 *
76 * Assumes single threaded execution
77 *
78 */
79
Mark Salyzyne1f20042015-05-06 08:40:40 -070080int android_log_addFilterRule(AndroidLogFormat *p_format,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080081 const char *filterExpression);
82
83
Mark Salyzyne1f20042015-05-06 08:40:40 -070084/**
85 * filterString: a whitespace-separated set of filter expressions
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080086 * eg "AT:d *:i"
87 *
88 * returns 0 on success and -1 on invalid expression
89 *
90 * Assumes single threaded execution
91 *
92 */
93
94int android_log_addFilterString(AndroidLogFormat *p_format,
95 const char *filterString);
96
97
Mark Salyzyne1f20042015-05-06 08:40:40 -070098/**
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080099 * returns 1 if this log line should be printed based on its priority
100 * and tag, and 0 if it should not
101 */
102int android_log_shouldPrintLine (
103 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
104
105
106/**
107 * Splits a wire-format buffer into an AndroidLogEntry
108 * entry allocated by caller. Pointers will point directly into buf
109 *
110 * Returns 0 on success and -1 on invalid wire format (entry will be
111 * in unspecified state)
112 */
113int android_log_processLogBuffer(struct logger_entry *buf,
114 AndroidLogEntry *entry);
115
116/**
117 * Like android_log_processLogBuffer, but for binary logs.
118 *
119 * If "map" is non-NULL, it will be used to convert the log tag number
120 * into a string.
121 */
122int android_log_processBinaryLogBuffer(struct logger_entry *buf,
123 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
124 int messageBufLen);
125
126
127/**
128 * Formats a log message into a buffer
129 *
130 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
131 * If return value != defaultBuffer, caller must call free()
132 * Returns NULL on malloc error
133 */
134
Mark Salyzyne1f20042015-05-06 08:40:40 -0700135char *android_log_formatLogLine (
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800136 AndroidLogFormat *p_format,
137 char *defaultBuffer,
138 size_t defaultBufferSize,
139 const AndroidLogEntry *p_line,
140 size_t *p_outLength);
141
142
143/**
144 * Either print or do not print log line, based on filter
145 *
146 * Assumes single threaded execution
147 *
148 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800149int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800150 AndroidLogFormat *p_format,
151 int fd,
152 const AndroidLogEntry *entry);
153
154
155#ifdef __cplusplus
156}
157#endif
158
159
160#endif /*_LOGPRINT_H*/