2009-03-04 04:32:55 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LOGPRINT_H
|
|
|
|
#define _LOGPRINT_H
|
|
|
|
|
2013-07-24 01:59:20 +02:00
|
|
|
#include <log/log.h>
|
|
|
|
#include <log/logger.h>
|
|
|
|
#include <log/event_tag_map.h>
|
2009-03-04 04:32:55 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FORMAT_OFF = 0,
|
|
|
|
FORMAT_BRIEF,
|
|
|
|
FORMAT_PROCESS,
|
|
|
|
FORMAT_TAG,
|
|
|
|
FORMAT_THREAD,
|
|
|
|
FORMAT_RAW,
|
|
|
|
FORMAT_TIME,
|
|
|
|
FORMAT_THREADTIME,
|
|
|
|
FORMAT_LONG,
|
2015-08-31 17:01:33 +02:00
|
|
|
/* The following are modifiers to above formats */
|
2015-05-06 17:40:40 +02:00
|
|
|
FORMAT_MODIFIER_COLOR, /* converts priority to color */
|
|
|
|
FORMAT_MODIFIER_TIME_USEC, /* switches from msec to usec time precision */
|
2015-05-15 18:01:58 +02:00
|
|
|
FORMAT_MODIFIER_PRINTABLE, /* converts non-printable to printable escapes */
|
2015-08-31 17:01:33 +02:00
|
|
|
FORMAT_MODIFIER_YEAR, /* Adds year to date */
|
|
|
|
FORMAT_MODIFIER_ZONE, /* Adds zone to date */
|
2015-09-01 00:53:41 +02:00
|
|
|
FORMAT_MODIFIER_EPOCH, /* Print time as seconds since Jan 1 1970 */
|
|
|
|
FORMAT_MODIFIER_MONOTONIC, /* Print cpu time as seconds since start */
|
2015-12-08 01:52:42 +01:00
|
|
|
FORMAT_MODIFIER_UID, /* Adds uid */
|
2009-03-04 04:32:55 +01:00
|
|
|
} AndroidLogPrintFormat;
|
|
|
|
|
|
|
|
typedef struct AndroidLogFormat_t AndroidLogFormat;
|
|
|
|
|
|
|
|
typedef struct AndroidLogEntry_t {
|
|
|
|
time_t tv_sec;
|
|
|
|
long tv_nsec;
|
|
|
|
android_LogPriority priority;
|
2015-12-08 01:52:42 +01:00
|
|
|
int32_t uid;
|
2012-02-28 01:48:18 +01:00
|
|
|
int32_t pid;
|
|
|
|
int32_t tid;
|
2009-03-04 04:32:55 +01:00
|
|
|
const char * tag;
|
|
|
|
size_t messageLen;
|
|
|
|
const char * message;
|
|
|
|
} AndroidLogEntry;
|
|
|
|
|
|
|
|
AndroidLogFormat *android_log_format_new();
|
|
|
|
|
|
|
|
void android_log_format_free(AndroidLogFormat *p_format);
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
/* currently returns 0 if format is a modifier, 1 if not */
|
|
|
|
int android_log_setPrintFormat(AndroidLogFormat *p_format,
|
2009-03-04 04:32:55 +01:00
|
|
|
AndroidLogPrintFormat format);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns FORMAT_OFF on invalid string
|
|
|
|
*/
|
|
|
|
AndroidLogPrintFormat android_log_formatFromString(const char *s);
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
/**
|
2009-03-04 04:32:55 +01:00
|
|
|
* filterExpression: a single filter expression
|
|
|
|
* eg "AT:d"
|
|
|
|
*
|
|
|
|
* returns 0 on success and -1 on invalid expression
|
|
|
|
*
|
|
|
|
* Assumes single threaded execution
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
int android_log_addFilterRule(AndroidLogFormat *p_format,
|
2009-03-04 04:32:55 +01:00
|
|
|
const char *filterExpression);
|
|
|
|
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
/**
|
|
|
|
* filterString: a whitespace-separated set of filter expressions
|
2009-03-04 04:32:55 +01:00
|
|
|
* eg "AT:d *:i"
|
|
|
|
*
|
|
|
|
* returns 0 on success and -1 on invalid expression
|
|
|
|
*
|
|
|
|
* Assumes single threaded execution
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int android_log_addFilterString(AndroidLogFormat *p_format,
|
|
|
|
const char *filterString);
|
|
|
|
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
/**
|
2009-03-04 04:32:55 +01:00
|
|
|
* returns 1 if this log line should be printed based on its priority
|
|
|
|
* and tag, and 0 if it should not
|
|
|
|
*/
|
|
|
|
int android_log_shouldPrintLine (
|
|
|
|
AndroidLogFormat *p_format, const char *tag, android_LogPriority pri);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Splits a wire-format buffer into an AndroidLogEntry
|
|
|
|
* entry allocated by caller. Pointers will point directly into buf
|
|
|
|
*
|
|
|
|
* Returns 0 on success and -1 on invalid wire format (entry will be
|
|
|
|
* in unspecified state)
|
|
|
|
*/
|
|
|
|
int android_log_processLogBuffer(struct logger_entry *buf,
|
|
|
|
AndroidLogEntry *entry);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Like android_log_processLogBuffer, but for binary logs.
|
|
|
|
*
|
|
|
|
* If "map" is non-NULL, it will be used to convert the log tag number
|
|
|
|
* into a string.
|
|
|
|
*/
|
|
|
|
int android_log_processBinaryLogBuffer(struct logger_entry *buf,
|
|
|
|
AndroidLogEntry *entry, const EventTagMap* map, char* messageBuf,
|
|
|
|
int messageBufLen);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a log message into a buffer
|
|
|
|
*
|
|
|
|
* Uses defaultBuffer if it can, otherwise malloc()'s a new buffer
|
|
|
|
* If return value != defaultBuffer, caller must call free()
|
|
|
|
* Returns NULL on malloc error
|
|
|
|
*/
|
|
|
|
|
2015-05-06 17:40:40 +02:00
|
|
|
char *android_log_formatLogLine (
|
2009-03-04 04:32:55 +01:00
|
|
|
AndroidLogFormat *p_format,
|
|
|
|
char *defaultBuffer,
|
|
|
|
size_t defaultBufferSize,
|
|
|
|
const AndroidLogEntry *p_line,
|
|
|
|
size_t *p_outLength);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Either print or do not print log line, based on filter
|
|
|
|
*
|
|
|
|
* Assumes single threaded execution
|
|
|
|
*
|
|
|
|
*/
|
2010-03-01 18:11:54 +01:00
|
|
|
int android_log_printLogLine(
|
2009-03-04 04:32:55 +01:00
|
|
|
AndroidLogFormat *p_format,
|
|
|
|
int fd,
|
|
|
|
const AndroidLogEntry *entry);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /*_LOGPRINT_H*/
|