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 <log/log.h> 21 #include <log/logger.h> 22 #include <log/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 /* The following are modifiers to above formats */ 40 FORMAT_MODIFIER_COLOR, /* converts priority to color */ 41 FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */ 42 FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */ 43 FORMAT_MODIFIER_YEAR, /* Adds year to date */ 44 FORMAT_MODIFIER_ZONE, /* Adds zone to date */ 45 FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */ 46 FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */ 47 FORMAT_MODIFIER_UID, /* Adds uid */ 48 } AndroidLogPrintFormat; 49 50 typedef struct AndroidLogFormat_t AndroidLogFormat; 51 52 typedef struct AndroidLogEntry_t { 53 time_t tv_sec; 54 long tv_nsec; 55 android_LogPriority priority; 56 int32_t uid; 57 int32_t pid; 58 int32_t tid; 59 const char * tag; 60 size_t messageLen; 61 const char * message; 62 } AndroidLogEntry; 63 64 AndroidLogFormat *android_log_format_new(); 65 66 void android_log_format_free(AndroidLogFormat *p_format); 67 68 /* currently returns 0 if format is a modifier, 1 if not */ 69 int android_log_setPrintFormat(AndroidLogFormat *p_format, 70 AndroidLogPrintFormat format); 71 72 /** 73 * Returns FORMAT_OFF on invalid string 74 */ 75 AndroidLogPrintFormat android_log_formatFromString(const char *s); 76 77 /** 78 * filterExpression: a single filter expression 79 * eg "AT:d" 80 * 81 * returns 0 on success and -1 on invalid expression 82 * 83 * Assumes single threaded execution 84 * 85 */ 86 87 int android_log_addFilterRule(AndroidLogFormat *p_format, 88 const char *filterExpression); 89 90 91 /** 92 * filterString: a whitespace-separated set of filter expressions 93 * eg "AT:d *:i" 94 * 95 * returns 0 on success and -1 on invalid expression 96 * 97 * Assumes single threaded execution 98 * 99 */ 100 101 int android_log_addFilterString(AndroidLogFormat *p_format, 102 const char *filterString); 103 104 105 /** 106 * returns 1 if this log line should be printed based on its priority 107 * and tag, and 0 if it should not 108 */ 109 int android_log_shouldPrintLine ( 110 AndroidLogFormat *p_format, const char *tag, android_LogPriority pri); 111 112 113 /** 114 * Splits a wire-format buffer into an AndroidLogEntry 115 * entry allocated by caller. Pointers will point directly into buf 116 * 117 * Returns 0 on success and -1 on invalid wire format (entry will be 118 * in unspecified state) 119 */ 120 int android_log_processLogBuffer(struct logger_entry *buf, 121 AndroidLogEntry *entry); 122 123 /** 124 * Like android_log_processLogBuffer, but for binary logs. 125 * 126 * If "map" is non-NULL, it will be used to convert the log tag number 127 * into a string. 128 */ 129 int android_log_processBinaryLogBuffer(struct logger_entry *buf, 130 AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf, 131 int messageBufLen); 132 133 134 /** 135 * Formats a log message into a buffer 136 * 137 * Uses defaultBuffer if it can, otherwise malloc()'s a new buffer 138 * If return value != defaultBuffer, caller must call free() 139 * Returns NULL on malloc error 140 */ 141 142 char *android_log_formatLogLine ( 143 AndroidLogFormat *p_format, 144 char *defaultBuffer, 145 size_t defaultBufferSize, 146 const AndroidLogEntry *p_line, 147 size_t *p_outLength); 148 149 150 /** 151 * Either print or do not print log line, based on filter 152 * 153 * Assumes single threaded execution 154 * 155 */ 156 int android_log_printLogLine( 157 AndroidLogFormat *p_format, 158 int fd, 159 const AndroidLogEntry *entry); 160 161 162 #ifdef __cplusplus 163 } 164 #endif 165 166 167 #endif /*_LOGPRINT_H*/ 168