Adding a way for log-format numbers to become more human readable.
authorWayne Davison <wayned@samba.org>
Tue, 17 Feb 2009 21:22:28 +0000 (13:22 -0800)
committerWayne Davison <wayned@samba.org>
Wed, 18 Feb 2009 15:26:48 +0000 (07:26 -0800)
NEWS
log.c
rsyncd.conf.yo

diff --git a/NEWS b/NEWS
index 073909e..89f79ce 100644 (file)
--- 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.
 
       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.
 
 
     - Added a "T" (terabyte) category to the --human-readable size suffixes.
 
diff --git a/log.c b/log.c
index adde3c8..a687375 100644 (file)
--- 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; ) {
        buf[total] = '\0';
 
        for (p = buf; (p = strchr(p, '%')) != NULL; ) {
+               int humanize = 0;
                s = p++;
                c = fmt + 1;
                s = p++;
                c = fmt + 1;
+               while (*p == '\'') {
+                       humanize++;
+                       p++;
+               }
                if (*p == '-')
                        *c++ = *p++;
                while (isDigit(p) && c - fmt < (int)(sizeof fmt) - 8)
                        *c++ = *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';
                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,
                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':
                        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);
                                        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':
                        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);
                                        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':
                        n = buf2;
                        break;
                case 'C':
index 992b7ce..b6954ba 100644 (file)
@@ -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)").
 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.
 
 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.