On Mon, Feb 16, 2009 at 09:29:38PM -0600, Kent Vander Velden wrote:
> Is there an alternative format type that lists the file length in a
> human readable format, perhaps optionally if --human-readable is
> specified?

No, nothing like that currently exists.  The master branch in git (that
will become 3.1.0) currently outputs log numbers with comma groupings,
but it would be much better to only do that if the user requests such a
thing.

The attached patch adds an apostrophe modifier to log escapes that lets
the user request numerical grouping, human-readable units of 1000, or
human-readable units of 1024; e.g. "%''l".  The patch will not work with
3.0.x, though.

..wayne..
--- 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':
--- a/rsyncd.conf.yo
+++ b/rsyncd.conf.yo
@@ -525,6 +525,12 @@ 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)").
 
+Finally, 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 the bf(--human-readable) command-line option
+to rsync, though the default is for human-readability to be off instead of at
+level 1.  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.
 (A perl script that will summarize this default log format is included
-- 
Please use reply-all for most replies to avoid omitting the mailing list.
To unsubscribe or change options: https://lists.samba.org/mailman/listinfo/rsync
Before posting, read: http://www.catb.org/~esr/faqs/smart-questions.html

Reply via email to