| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | /* | 
|  | 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 |  | 
|  | 20 | #include <cutils/log.h> | 
|  | 21 | #include <cutils/logger.h> | 
|  | 22 | #include <cutils/event_tag_map.h> | 
|  | 23 | #include <pthread.h> | 
|  | 24 |  | 
|  | 25 | #ifdef __cplusplus | 
|  | 26 | extern "C" { | 
|  | 27 | #endif | 
|  | 28 |  | 
|  | 29 | typedef 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 |  | 
|  | 41 | typedef struct AndroidLogFormat_t AndroidLogFormat; | 
|  | 42 |  | 
|  | 43 | typedef struct AndroidLogEntry_t { | 
|  | 44 | time_t tv_sec; | 
|  | 45 | long tv_nsec; | 
|  | 46 | android_LogPriority priority; | 
| Andrew Hsieh | d2c8f52 | 2012-02-27 16:48:18 -0800 | [diff] [blame] | 47 | int32_t pid; | 
|  | 48 | int32_t tid; | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 49 | const char * tag; | 
|  | 50 | size_t messageLen; | 
|  | 51 | const char * message; | 
|  | 52 | } AndroidLogEntry; | 
|  | 53 |  | 
|  | 54 | AndroidLogFormat *android_log_format_new(); | 
|  | 55 |  | 
|  | 56 | void android_log_format_free(AndroidLogFormat *p_format); | 
|  | 57 |  | 
|  | 58 | void android_log_setPrintFormat(AndroidLogFormat *p_format, | 
|  | 59 | AndroidLogPrintFormat format); | 
|  | 60 |  | 
|  | 61 | /** | 
|  | 62 | * Returns FORMAT_OFF on invalid string | 
|  | 63 | */ | 
|  | 64 | AndroidLogPrintFormat 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 |  | 
|  | 76 | int 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 |  | 
|  | 90 | int 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 | */ | 
|  | 98 | int 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 | */ | 
|  | 109 | int 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 | */ | 
|  | 118 | int 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 |  | 
|  | 131 | char *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 Onorato | e2bf2ea | 2010-03-01 09:11:54 -0800 | [diff] [blame] | 145 | int android_log_printLogLine( | 
| The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 146 | AndroidLogFormat *p_format, | 
|  | 147 | int fd, | 
|  | 148 | const AndroidLogEntry *entry); | 
|  | 149 |  | 
|  | 150 |  | 
|  | 151 | #ifdef __cplusplus | 
|  | 152 | } | 
|  | 153 | #endif | 
|  | 154 |  | 
|  | 155 |  | 
|  | 156 | #endif /*_LOGPRINT_H*/ |