Path: blob/21.2-virgl/include/android_stub/log/logprint.h
4547 views
/*1* Copyright (C) 2006 The Android Open Source Project2*3* Licensed under the Apache License, Version 2.0 (the "License");4* you may not use this file except in compliance with the License.5* You may obtain a copy of the License at6*7* http://www.apache.org/licenses/LICENSE-2.08*9* Unless required by applicable law or agreed to in writing, software10* distributed under the License is distributed on an "AS IS" BASIS,11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12* See the License for the specific language governing permissions and13* limitations under the License.14*/1516#pragma once1718#include <stdint.h>19#include <sys/types.h>2021#include <android/log.h>22#include <log/event_tag_map.h>2324#ifdef __cplusplus25extern "C" {26#endif2728typedef enum {29/* Verbs */30FORMAT_OFF = 0,31FORMAT_BRIEF,32FORMAT_PROCESS,33FORMAT_TAG,34FORMAT_THREAD,35FORMAT_RAW,36FORMAT_TIME,37FORMAT_THREADTIME,38FORMAT_LONG,39/* Adverbs. The following are modifiers to above format verbs */40FORMAT_MODIFIER_COLOR, /* converts priority to color */41FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */42FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */43FORMAT_MODIFIER_YEAR, /* Adds year to date */44FORMAT_MODIFIER_ZONE, /* Adds zone to date, + UTC */45FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */46FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */47FORMAT_MODIFIER_UID, /* Adds uid */48FORMAT_MODIFIER_DESCRIPT, /* Adds descriptive */49/* private, undocumented */50FORMAT_MODIFIER_TIME_NSEC, /* switches from msec to nsec time precision */51} AndroidLogPrintFormat;5253typedef struct AndroidLogFormat_t AndroidLogFormat;5455typedef struct AndroidLogEntry_t {56time_t tv_sec;57long tv_nsec;58android_LogPriority priority;59int32_t uid;60int32_t pid;61int32_t tid;62const char* tag;63size_t tagLen;64size_t messageLen;65const char* message;66} AndroidLogEntry;6768AndroidLogFormat* android_log_format_new();6970void android_log_format_free(AndroidLogFormat* p_format);7172/* currently returns 0 if format is a modifier, 1 if not */73int android_log_setPrintFormat(AndroidLogFormat* p_format,74AndroidLogPrintFormat format);7576/**77* Returns FORMAT_OFF on invalid string78*/79AndroidLogPrintFormat android_log_formatFromString(const char* s);8081/**82* filterExpression: a single filter expression83* eg "AT:d"84*85* returns 0 on success and -1 on invalid expression86*87* Assumes single threaded execution88*89*/9091int android_log_addFilterRule(AndroidLogFormat* p_format,92const char* filterExpression);9394/**95* filterString: a whitespace-separated set of filter expressions96* eg "AT:d *:i"97*98* returns 0 on success and -1 on invalid expression99*100* Assumes single threaded execution101*102*/103104int android_log_addFilterString(AndroidLogFormat* p_format,105const char* filterString);106107/**108* returns 1 if this log line should be printed based on its priority109* and tag, and 0 if it should not110*/111int android_log_shouldPrintLine(AndroidLogFormat* p_format, const char* tag,112android_LogPriority pri);113114/**115* Splits a wire-format buffer into an AndroidLogEntry116* entry allocated by caller. Pointers will point directly into buf117*118* Returns 0 on success and -1 on invalid wire format (entry will be119* in unspecified state)120*/121int android_log_processLogBuffer(struct logger_entry* buf,122AndroidLogEntry* entry);123124/**125* Like android_log_processLogBuffer, but for binary logs.126*127* If "map" is non-NULL, it will be used to convert the log tag number128* into a string.129*/130int android_log_processBinaryLogBuffer(struct logger_entry* buf,131AndroidLogEntry* entry,132const EventTagMap* map, char* messageBuf,133int messageBufLen);134135/**136* Formats a log message into a buffer137*138* Uses defaultBuffer if it can, otherwise malloc()'s a new buffer139* If return value != defaultBuffer, caller must call free()140* Returns NULL on malloc error141*/142143char* android_log_formatLogLine(AndroidLogFormat* p_format, char* defaultBuffer,144size_t defaultBufferSize,145const AndroidLogEntry* p_line,146size_t* p_outLength);147148/**149* Either print or do not print log line, based on filter150*151* Assumes single threaded execution152*153*/154int android_log_printLogLine(AndroidLogFormat* p_format, int fd,155const AndroidLogEntry* entry);156157#ifdef __cplusplus158}159#endif160161162