blob: 1e42b473949923345dcfb66709cfb84109c36a15 [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,
Pierre Zurekead88fc2010-10-17 22:39:37 +020039 FORMAT_COLOR,
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080040} AndroidLogPrintFormat;
41
42typedef struct AndroidLogFormat_t AndroidLogFormat;
43
44typedef struct AndroidLogEntry_t {
45 time_t tv_sec;
46 long tv_nsec;
47 android_LogPriority priority;
Andrew Hsiehd2c8f522012-02-27 16:48:18 -080048 int32_t pid;
49 int32_t tid;
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -080050 const char * tag;
51 size_t messageLen;
52 const char * message;
53} AndroidLogEntry;
54
55AndroidLogFormat *android_log_format_new();
56
57void android_log_format_free(AndroidLogFormat *p_format);
58
59void android_log_setPrintFormat(AndroidLogFormat *p_format,
60 AndroidLogPrintFormat format);
61
62/**
63 * Returns FORMAT_OFF on invalid string
64 */
65AndroidLogPrintFormat android_log_formatFromString(const char *s);
66
67/**
68 * filterExpression: a single filter expression
69 * eg "AT:d"
70 *
71 * returns 0 on success and -1 on invalid expression
72 *
73 * Assumes single threaded execution
74 *
75 */
76
77int android_log_addFilterRule(AndroidLogFormat *p_format,
78 const char *filterExpression);
79
80
81/**
82 * filterString: a whitespace-separated set of filter expressions
83 * eg "AT:d *:i"
84 *
85 * returns 0 on success and -1 on invalid expression
86 *
87 * Assumes single threaded execution
88 *
89 */
90
91int android_log_addFilterString(AndroidLogFormat *p_format,
92 const char *filterString);
93
94
95/**
96 * returns 1 if this log line should be printed based on its priority
97 * and tag, and 0 if it should not
98 */
99int android_log_shouldPrintLine (
100 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
101
102
103/**
104 * Splits a wire-format buffer into an AndroidLogEntry
105 * entry allocated by caller. Pointers will point directly into buf
106 *
107 * Returns 0 on success and -1 on invalid wire format (entry will be
108 * in unspecified state)
109 */
110int android_log_processLogBuffer(struct logger_entry *buf,
111 AndroidLogEntry *entry);
112
113/**
114 * Like android_log_processLogBuffer, but for binary logs.
115 *
116 * If "map" is non-NULL, it will be used to convert the log tag number
117 * into a string.
118 */
119int android_log_processBinaryLogBuffer(struct logger_entry *buf,
120 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
121 int messageBufLen);
122
123
124/**
125 * Formats a log message into a buffer
126 *
127 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
128 * If return value != defaultBuffer, caller must call free()
129 * Returns NULL on malloc error
130 */
131
132char *android_log_formatLogLine (
133 AndroidLogFormat *p_format,
134 char *defaultBuffer,
135 size_t defaultBufferSize,
136 const AndroidLogEntry *p_line,
137 size_t *p_outLength);
138
139
140/**
141 * Either print or do not print log line, based on filter
142 *
143 * Assumes single threaded execution
144 *
145 */
Joe Onoratoe2bf2ea2010-03-01 09:11:54 -0800146int android_log_printLogLine(
The Android Open Source Projectdd7bc332009-03-03 19:32:55 -0800147 AndroidLogFormat *p_format,
148 int fd,
149 const AndroidLogEntry *entry);
150
151
152#ifdef __cplusplus
153}
154#endif
155
156
157#endif /*_LOGPRINT_H*/