From: Wayne Davison Date: Tue, 17 Feb 2009 21:22:28 +0000 (-0800) Subject: Adding a way for log-format numbers to become more human readable. X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/commitdiff_plain/df7ec1cf428ef45f255589a5ca662cfb25724510 Adding a way for log-format numbers to become more human readable. --- diff --git a/NEWS b/NEWS index 073909e7..89f79ce9 100644 --- a/NEWS +++ b/NEWS @@ -16,8 +16,10 @@ Changes since 3.0.4: control over what is output. Added an extra type of --progress output using --info=progress2. - - Output numbers in 3-digit groups by default (e.g. 1,234,567). (See the - --human-readable option for a way to turn it off.) + - Output numbers in 3-digit groups by default (e.g. 1,234,567). See the + --human-readable option for a way to turn it off. See also the daemon's + "log format" parameter for a modifier that can request digit-grouping or + human-readable output in log escapes (including --out-format). - Added a "T" (terabyte) category to the --human-readable size suffixes. diff --git a/log.c b/log.c index adde3c8e..a6873750 100644 --- a/log.c +++ b/log.c @@ -493,12 +493,21 @@ static void log_formatted(enum logcode code, const char *format, const char *op, buf[total] = '\0'; for (p = buf; (p = strchr(p, '%')) != NULL; ) { + int humanize = 0; s = p++; c = fmt + 1; + while (*p == '\'') { + humanize++; + p++; + } if (*p == '-') *c++ = *p++; while (isDigit(p) && c - fmt < (int)(sizeof fmt) - 8) *c++ = *p++; + while (*p == '\'') { + humanize++; + p++; + } if (!*p) break; *c = '\0'; @@ -522,7 +531,7 @@ static void log_formatted(enum logcode code, const char *format, const char *op, case 'l': strlcat(fmt, "s", sizeof fmt); snprintf(buf2, sizeof buf2, fmt, - comma_num(F_LENGTH(file))); + do_big_num(F_LENGTH(file), humanize, NULL)); n = buf2; break; case 'U': @@ -639,7 +648,8 @@ static void log_formatted(enum logcode code, const char *format, const char *op, initial_stats->total_read; } strlcat(fmt, "s", sizeof fmt); - snprintf(buf2, sizeof buf2, fmt, comma_num(b)); + snprintf(buf2, sizeof buf2, fmt, + do_big_num(b, humanize, NULL)); n = buf2; break; case 'c': @@ -651,7 +661,8 @@ static void log_formatted(enum logcode code, const char *format, const char *op, initial_stats->total_read; } strlcat(fmt, "s", sizeof fmt); - snprintf(buf2, sizeof buf2, fmt, comma_num(b)); + snprintf(buf2, sizeof buf2, fmt, + do_big_num(b, humanize, NULL)); n = buf2; break; case 'C': diff --git a/rsyncd.conf.yo b/rsyncd.conf.yo index 992b7cee..b6954baf 100644 --- a/rsyncd.conf.yo +++ b/rsyncd.conf.yo @@ -524,6 +524,11 @@ The format is a text string containing embedded single-character escape sequences prefixed with a percent (%) character. An optional numeric field width may also be specified between the percent and the escape letter (e.g. "bf(%-50n %8l %07p)"). +In addition, one or more apostrophes may be specified prior to a numerical +escape to indicate that the numerical value should be made more human-readable. +The 3 supported levels are the same as for the bf(--human-readable) +command-line option, though the default is for human-readability to be off. +Each added apostrophe increases the level (e.g. "bf(%''l %'b %f)"). The default log format is "%o %h [%a] %m (%u) %f %l", and a "%t [%p] " is always prefixed when using the "log file" parameter.