added the --log-format option to allow users to request arbitrary
authorAndrew Tridgell <tridge@samba.org>
Tue, 3 Nov 1998 03:48:47 +0000 (03:48 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 3 Nov 1998 03:48:47 +0000 (03:48 +0000)
per-file logging of interactive rsync sessions.

log.c
options.c
rsync.yo
rsyncd.conf.yo

diff --git a/log.c b/log.c
index 654346208484277feb43ab8c60655b75095f5e7b..62572da5a05830b9f4d28cb59b116f291efb0b69 100644 (file)
--- a/log.c
+++ b/log.c
@@ -174,7 +174,8 @@ void rflush(int fd)
 
 /* a generic logging routine for send/recv, with parameter
    substitiution */
-static void log_formatted(char *op, struct file_struct *file,
+static void log_formatted(int fd,
+                         char *format, char *op, struct file_struct *file,
                          struct stats *initial_stats)
 {
        extern int module_id;
@@ -187,7 +188,7 @@ static void log_formatted(char *op, struct file_struct *file,
        extern int am_sender;
        int64 b;
 
-       strlcpy(buf, lp_log_format(module_id), sizeof(buf)-1);
+       strlcpy(buf, format, sizeof(buf)-1);
        
        for (s=&buf[0]; 
             s && (p=strchr(s,'%')); ) {
@@ -214,8 +215,10 @@ static void log_formatted(char *op, struct file_struct *file,
                                 f_name(file));
                        clean_fname(buf2);
                        n = buf2; 
+                       if (*n == '/') n++;
                        break;
                case 'm': n = lp_name(module_id); break;
+               case 't': n = timestring(time(NULL)); break;
                case 'P': n = lp_path(module_id); break;
                case 'u': n = auth_user; break;
                case 'b': 
@@ -260,15 +263,20 @@ static void log_formatted(char *op, struct file_struct *file,
                s = p+l;
        }
 
-       rprintf(FLOG,"%s\n", buf);
+       rprintf(fd,"%s\n", buf);
 }
 
 /* log the outgoing transfer of a file */
 void log_send(struct file_struct *file, struct stats *initial_stats)
 {
        extern int module_id;
+       extern int am_server;
+       extern char *log_format;
+
        if (lp_transfer_logging(module_id)) {
-               log_formatted("send", file, initial_stats);
+               log_formatted(FLOG, lp_log_format(module_id), "send", file, initial_stats);
+       } else if (log_format && !am_server) {
+               log_formatted(FINFO, log_format, "send", file, initial_stats);
        }
 }
 
@@ -276,8 +284,13 @@ void log_send(struct file_struct *file, struct stats *initial_stats)
 void log_recv(struct file_struct *file, struct stats *initial_stats)
 {
        extern int module_id;
+       extern int am_server;
+       extern char *log_format;
+
        if (lp_transfer_logging(module_id)) {
-               log_formatted("recv", file, initial_stats);
+               log_formatted(FLOG, lp_log_format(module_id), "send", file, initial_stats);
+       } else if (log_format && !am_server) {
+               log_formatted(FINFO, log_format, "send", file, initial_stats);
        }
 }
 
@@ -296,7 +309,10 @@ void log_exit(int code)
 }
 
 /* log the incoming transfer of a file for interactive use, this
-   will be called at the end where the client was run */
+   will be called at the end where the client was run 
+   
+   it i called when a file starts to be transferred
+*/
 void log_transfer(struct file_struct *file, char *fname)
 {
        extern int verbose;
index 082aad77cc871fd88ba3d6411719e0e4d27fa7bf..09a13c49b2bce423b5ff70f2bb3479276c87ffbb 100644 (file)
--- a/options.c
+++ b/options.c
@@ -67,6 +67,7 @@ char *tmpdir = NULL;
 char *compare_dest = NULL;
 char *config_file = RSYNCD_CONF;
 char *shell_cmd = NULL;
+char *log_format = NULL;
 
 char *rsync_path = RSYNC_NAME;
 int rsync_port = RSYNC_PORT;
@@ -132,6 +133,7 @@ void usage(int F)
   rprintf(F,"     --port=PORT             specify alternate rsyncd port number\n");
   rprintf(F,"     --stats                 give some file transfer stats\n");  
   rprintf(F,"     --progress              show progress during transfer\n");  
+  rprintf(F,"     --log-format=FORMAT     log file transfers using specified format\n");  
   rprintf(F," -h, --help                  show this help screen\n");
 
   rprintf(F,"\n");
@@ -146,7 +148,7 @@ enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
       OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
       OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON,OPT_CONFIG,OPT_PORT,
       OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_STATS, OPT_PARTIAL, OPT_PROGRESS,
-      OPT_SAFE_LINKS, OPT_COMPARE_DEST};
+      OPT_SAFE_LINKS, OPT_COMPARE_DEST, OPT_LOG_FORMAT};
 
 static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
 
@@ -198,6 +200,7 @@ static struct option long_options[] = {
   {"partial",     0,     0,    OPT_PARTIAL},
   {"config",      1,     0,    OPT_CONFIG},
   {"port",        1,     0,    OPT_PORT},
+  {"log-format",  1,     0,    OPT_LOG_FORMAT},
   {0,0,0,0}};
 
 
@@ -419,6 +422,10 @@ int parse_arguments(int argc, char *argv[])
                        rsync_port = atoi(optarg);
                        break;
 
+               case OPT_LOG_FORMAT:
+                       log_format = optarg;
+                       break;
+
                default:
                        return 0;
                }
index aa7a94c40231d11749bf36377c523393c180aa2e..04178ff67ee73aac2062b02581c3baa1feb35099 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -254,6 +254,7 @@ Options
      --port=PORT             specify alternate rsyncd port number
      --stats                 give some file transfer stats
      --progress              show progress during transfer
+     --log-format=FORMAT     log file transfers using specified format
  -h, --help                  show this help screen
 )
 
@@ -549,6 +550,11 @@ specified.
 dit(bf(--port PORT)) This specifies an alternate TCP port number to use
 rather than the default port 873. 
 
+dit(bf(--log-format=FORMAT)) Normally rsync just logs filenames as
+they are transferred. This allows you to specify exactly what gets
+logged on a per file basis. The log format is specified using the same
+format conventions as the log format option in rsyncd.conf.
+
 dit(bf(--stats)) This tells rsync to print a verbose set of statistics
 on the file transfer, allowing you to tell how effective the rsync
 algorithm is for your data. This option only works in conjunction with
index 2b01601b462937c555a9637fd0248a2cd656739b..faa31c5a32289364871a0b6fa5a82be4b06e1f82 100644 (file)
@@ -128,6 +128,7 @@ itemize(
   it() %f for the filename
   it() %P for the module path
   it() %m for the module name
+  it() %t for the current time
   it() %u for the authenticated username (or the null string)
   it() %b for the number of bytes actually transferred 
   it() %c when sending files this gives the number of checksum bytes