diff --git a/include/log/logprint.h b/include/log/logprint.h
index 481c96e..6f9962e 100644
--- a/include/log/logprint.h
+++ b/include/log/logprint.h
@@ -36,6 +36,7 @@ typedef enum {
FORMAT_TIME,
FORMAT_THREADTIME,
FORMAT_LONG,
+ FORMAT_DETECTOR,
} AndroidLogPrintFormat;
typedef struct AndroidLogFormat_t AndroidLogFormat;
@@ -58,6 +59,11 @@ void android_log_format_free(AndroidLogFormat *p_format);
void android_log_setPrintFormat(AndroidLogFormat *p_format,
AndroidLogPrintFormat format);
+void android_log_setLogTag(AndroidLogFormat *p_format,const char *tag);
+
+void android_log_setLogPri(AndroidLogFormat *p_format, int pri);
+void android_log_setLogHost(AndroidLogFormat *p_format,const char *host);
+
/**
* Returns FORMAT_OFF on invalid string
*/
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 508c825..a24ea1a 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -29,6 +29,9 @@
#include <log/logd.h>
#include <log/logprint.h>
typedef struct FilterInfo_t {
char *mTag;
android_LogPriority mPri;
@@ -39,6 +42,9 @@ struct AndroidLogFormat_t {
android_LogPriority global_pri;
FilterInfo *filters;
AndroidLogPrintFormat format;
+ char *detector_tag;
+ int detector_pri;
+ char *detector_host;
};
static FilterInfo * filterinfo_new(const char * tag, android_LogPriority pri)
@@ -202,6 +208,18 @@ void android_log_setPrintFormat(AndroidLogFormat *p_format,
p_format->format=format;
}
+void android_log_setLogTag(AndroidLogFormat *p_format,const char *tag){
+ p_format->detector_tag=tag;
+}
+
+void android_log_setLogPri(AndroidLogFormat *p_format,int pri){
+ p_format->detector_pri=pri;
+}
+
+void android_log_setLogHost(AndroidLogFormat *p_format,const char *host){
+ p_format->detector_host=host;
+}
+
/**
* Returns FORMAT_OFF on invalid string
*/
@@ -217,6 +235,7 @@ AndroidLogPrintFormat android_log_formatFromString(const char * formatString)
else if (strcmp(formatString, "time") == 0) format = FORMAT_TIME;
else if (strcmp(formatString, "threadtime") == 0) format = FORMAT_THREADTIME;
else if (strcmp(formatString, "long") == 0) format = FORMAT_LONG;
+ else if (strcmp(formatString, "detector") == 0) format = FORMAT_DETECTOR;
else format = FORMAT_OFF;
return format;
@@ -709,12 +728,12 @@ char *android_log_formatLogLine (
#endif
struct tm* ptm;
char timeBuf[32];
+ char detector_timeBuf[32];
char headerBuf[128];
char prefixBuf[128], suffixBuf[128];
char priChar;
int prefixSuffixIsHeaderFooter = 0;
char * ret = NULL;
-
priChar = filterPriToChar(entry->priority);
/*
@@ -733,6 +752,7 @@ char *android_log_formatLogLine (
#endif
//strftime(timeBuf, sizeof(timeBuf), "%Y-%m-%d %H:%M:%S", ptm);
strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
+ strftime(detector_timeBuf, sizeof(detector_timeBuf), "%b %d %H:%M:%S", ptm);
/*
* Construct a buffer containing the log header and log message.
@@ -770,6 +790,13 @@ char *android_log_formatLogLine (
strcpy(suffixBuf, "\n");
suffixLen = 1;
break;
+ case FORMAT_DETECTOR:
+ prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
+ "<%d> %s %s %s ", p_format->detector_pri,detector_timeBuf,
+ p_format->detector_host, p_format->detector_tag);
+ strcpy(suffixBuf, "\n");
+ suffixLen = 1;
+ break;
case FORMAT_THREADTIME:
prefixLen = snprintf(prefixBuf, sizeof(prefixBuf),
"%s.%03ld %5d %5d %c %-8s: ", timeBuf, entry->tv_nsec / 1000000,
@@ -943,7 +970,6 @@ void logprint_run_tests()
int err;
const char *tag;
AndroidLogFormat *p_format;
-
p_format = android_log_format_new();
fprintf(stderr, "running tests\n");
diff --git a/logcat/logcat.cpp b/logcat/logcat.cpp
old mode 100644
new mode 100755
index d44c679..206478e
--- a/logcat/logcat.cpp
+++ b/logcat/logcat.cpp
@@ -452,6 +452,7 @@ static int setLogFormat(const char * formatString)
return 0;
}
+
extern "C" void logprint_run_tests(void);
int main(int argc, char **argv)
@@ -481,7 +482,7 @@ int main(int argc, char **argv)
for (;;) {
int ret;
- ret = getopt(argc, argv, "cdt:gsQf:r::n:v:b:B");
+ ret = getopt(argc, argv, "cdt:gsQf:r::n:v:b:T:m:p:B");
if (ret < 0) {
break;
@@ -533,6 +534,16 @@ int main(int argc, char **argv)
android::g_devCount++;
}
break;
+
+ case 'T':
+ android_log_setLogTag(g_logformat,optarg);
+ break;
+ case 'm':
+ android_log_setLogHost(g_logformat,optarg);
+ break;
+ case 'p':
+ android_log_setLogPri(g_logformat,atoi(optarg));
+ break;
case 'B':
android::g_printBinary = 1;
@@ -583,6 +594,7 @@ int main(int argc, char **argv)
hasSetLogFormat = 1;
break;
+
case 'Q':
/* this is a *hidden* option used to start a version of logcat */
/* in an emulated device only. it basically looks for androidboot.logcat= */
改造后的logcat 增加了一个格式:detector(时间打印的等等不一样...)
多传了几个参数,如:
logcat -v detector -T a -m b -p 1024
将得到如下打印:
<1024> Jan 01 08:00:06 b a Chinamobile IPTV Display Manager
而改造前的打印为:
01-01 08:00:06.210 I/SystemServer( 5223): System Write Manager
网友评论