2 * Copyright (C) 2006 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <sys/types.h>
22 #include <android/log.h>
23 #include <log/event_tag_map.h>
40 /* Adverbs. The following are modifiers to above format verbs */
41 FORMAT_MODIFIER_COLOR
, /* converts priority to color */
42 FORMAT_MODIFIER_TIME_USEC
, /* switches from msec to usec time precision */
43 FORMAT_MODIFIER_PRINTABLE
, /* converts non-printable to printable escapes */
44 FORMAT_MODIFIER_YEAR
, /* Adds year to date */
45 FORMAT_MODIFIER_ZONE
, /* Adds zone to date, + UTC */
46 FORMAT_MODIFIER_EPOCH
, /* Print time as seconds since Jan 1 1970 */
47 FORMAT_MODIFIER_MONOTONIC
, /* Print cpu time as seconds since start */
48 FORMAT_MODIFIER_UID
, /* Adds uid */
49 FORMAT_MODIFIER_DESCRIPT
, /* Adds descriptive */
50 /* private, undocumented */
51 FORMAT_MODIFIER_TIME_NSEC
, /* switches from msec to nsec time precision */
52 } AndroidLogPrintFormat
;
54 typedef struct AndroidLogFormat_t AndroidLogFormat
;
56 typedef struct AndroidLogEntry_t
{
59 android_LogPriority priority
;
69 AndroidLogFormat
* android_log_format_new();
71 void android_log_format_free(AndroidLogFormat
* p_format
);
73 /* currently returns 0 if format is a modifier, 1 if not */
74 int android_log_setPrintFormat(AndroidLogFormat
* p_format
,
75 AndroidLogPrintFormat format
);
78 * Returns FORMAT_OFF on invalid string
80 AndroidLogPrintFormat
android_log_formatFromString(const char* s
);
83 * filterExpression: a single filter expression
86 * returns 0 on success and -1 on invalid expression
88 * Assumes single threaded execution
92 int android_log_addFilterRule(AndroidLogFormat
* p_format
,
93 const char* filterExpression
);
96 * filterString: a whitespace-separated set of filter expressions
99 * returns 0 on success and -1 on invalid expression
101 * Assumes single threaded execution
105 int android_log_addFilterString(AndroidLogFormat
* p_format
,
106 const char* filterString
);
109 * returns 1 if this log line should be printed based on its priority
110 * and tag, and 0 if it should not
112 int android_log_shouldPrintLine(AndroidLogFormat
* p_format
, const char* tag
,
113 android_LogPriority pri
);
116 * Splits a wire-format buffer into an AndroidLogEntry
117 * entry allocated by caller. Pointers will point directly into buf
119 * Returns 0 on success and -1 on invalid wire format (entry will be
120 * in unspecified state)
122 int android_log_processLogBuffer(struct logger_entry
* buf
,
123 AndroidLogEntry
* entry
);
126 * Like android_log_processLogBuffer, but for binary logs.
128 * If "map" is non-NULL, it will be used to convert the log tag number
131 int android_log_processBinaryLogBuffer(struct logger_entry
* buf
,
132 AndroidLogEntry
* entry
,
133 const EventTagMap
* map
, char* messageBuf
,
137 * Formats a log message into a buffer
139 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
140 * If return value != defaultBuffer, caller must call free()
141 * Returns NULL on malloc error
144 char* android_log_formatLogLine(AndroidLogFormat
* p_format
, char* defaultBuffer
,
145 size_t defaultBufferSize
,
146 const AndroidLogEntry
* p_line
,
147 size_t* p_outLength
);
150 * Either print or do not print log line, based on filter
152 * Assumes single threaded execution
155 int android_log_printLogLine(AndroidLogFormat
* p_format
, int fd
,
156 const AndroidLogEntry
* entry
);