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