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