summaryrefslogtreecommitdiffstats
path: root/liblog
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2015-05-06 08:40:40 -0700
committerMark Salyzyn <salyzyn@google.com>2015-05-13 09:22:51 -0700
commit79c3815ca191033bd97e7d4458970b606f661a18 (patch)
tree85587a97dbbd8fe013534d4b85ff6180f2d5c075 /liblog
parenta1aacb71f387c91d5fe383b8aaa5b0be2ec9cd3c (diff)
downloadsystem_core-79c3815ca191033bd97e7d4458970b606f661a18.zip
system_core-79c3815ca191033bd97e7d4458970b606f661a18.tar.gz
system_core-79c3815ca191033bd97e7d4458970b606f661a18.tar.bz2
logcat: liblog: Add "usec" format argument
(cherry pick from commit e1f2004ecc05ce2d5d4313d16c7791594643f2ef) - Add additional 3 digits of time precision for time output adding in the reporting of usec - Remove trailing space in header file Change-Id: Ifb560850b8e01080e126fbaeab640db71cce3eea
Diffstat (limited to 'liblog')
-rw-r--r--liblog/logprint.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/liblog/logprint.c b/liblog/logprint.c
index 0f01542..a3f1d7e 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -43,6 +43,7 @@ struct AndroidLogFormat_t {
FilterInfo *filters;
AndroidLogPrintFormat format;
bool colored_output;
+ bool usec_time_output;
};
/*
@@ -185,6 +186,7 @@ AndroidLogFormat *android_log_format_new()
p_ret->global_pri = ANDROID_LOG_VERBOSE;
p_ret->format = FORMAT_BRIEF;
p_ret->colored_output = false;
+ p_ret->usec_time_output = false;
return p_ret;
}
@@ -207,13 +209,19 @@ void android_log_format_free(AndroidLogFormat *p_format)
-void android_log_setPrintFormat(AndroidLogFormat *p_format,
+int android_log_setPrintFormat(AndroidLogFormat *p_format,
AndroidLogPrintFormat format)
{
- if (format == FORMAT_COLOR)
+ if (format == FORMAT_MODIFIER_COLOR) {
p_format->colored_output = true;
- else
- p_format->format = format;
+ return 0;
+ }
+ if (format == FORMAT_MODIFIER_TIME_USEC) {
+ p_format->usec_time_output = true;
+ return 0;
+ }
+ p_format->format = format;
+ return 1;
}
/**
@@ -231,7 +239,8 @@ 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, "color") == 0) format = FORMAT_COLOR;
+ else if (strcmp(formatString, "color") == 0) format = FORMAT_MODIFIER_COLOR;
+ else if (strcmp(formatString, "usec") == 0) format = FORMAT_MODIFIER_TIME_USEC;
else format = FORMAT_OFF;
return format;
@@ -745,7 +754,7 @@ char *android_log_formatLogLine (
struct tm tmBuf;
#endif
struct tm* ptm;
- char timeBuf[32];
+ char timeBuf[32]; /* good margin, 23+nul for msec, 26+nul for usec */
char prefixBuf[128], suffixBuf[128];
char priChar;
int prefixSuffixIsHeaderFooter = 0;
@@ -771,6 +780,14 @@ 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);
+ len = strlen(timeBuf);
+ if (p_format->usec_time_output) {
+ snprintf(timeBuf + len, sizeof(timeBuf) - len,
+ ".%06ld", entry->tv_nsec / 1000);
+ } else {
+ snprintf(timeBuf + len, sizeof(timeBuf) - len,
+ ".%03ld", entry->tv_nsec / 1000000);
+ }
/*
* Construct a buffer containing the log header and log message.
@@ -811,23 +828,21 @@ char *android_log_formatLogLine (
break;
case FORMAT_TIME:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%s.%03ld %c/%-8s(%5d): ", timeBuf, entry->tv_nsec / 1000000,
- priChar, entry->tag, entry->pid);
+ "%s %c/%-8s(%5d): ", timeBuf, priChar, entry->tag, entry->pid);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
case FORMAT_THREADTIME:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "%s.%03ld %5d %5d %c %-8s: ", timeBuf, entry->tv_nsec / 1000000,
+ "%s %5d %5d %c %-8s: ", timeBuf,
entry->pid, entry->tid, priChar, entry->tag);
strcpy(suffixBuf + suffixLen, "\n");
++suffixLen;
break;
case FORMAT_LONG:
len = snprintf(prefixBuf + prefixLen, sizeof(prefixBuf) - prefixLen,
- "[ %s.%03ld %5d:%5d %c/%-8s ]\n",
- timeBuf, entry->tv_nsec / 1000000, entry->pid,
- entry->tid, priChar, entry->tag);
+ "[ %s %5d:%5d %c/%-8s ]\n",
+ timeBuf, entry->pid, entry->tid, priChar, entry->tag);
strcpy(suffixBuf + suffixLen, "\n\n");
suffixLen += 2;
prefixSuffixIsHeaderFooter = 1;