httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1051582 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/rotatelogs.xml support/rotatelogs.c
Date Tue, 21 Dec 2010 17:52:43 GMT
Author: minfrin
Date: Tue Dec 21 17:52:43 2010
New Revision: 1051582

URL: http://svn.apache.org/viewvc?rev=1051582&view=rev
Log:
rotatelogs: Add -e option to write logs through to stdout for optional
further processing.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml
    httpd/httpd/trunk/support/rotatelogs.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1051582&r1=1051581&r2=1051582&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Dec 21 17:52:43 2010
@@ -2,6 +2,9 @@
 
 Changes with Apache 2.3.11
 
+  *) rotatelogs: Add -e option to write logs through to stdout for optional
+     further processing. [Graham Leggett]
+
   *) mod_ssl: Correctly read full lines in input filter when the line is
      incomplete during first read. PR 50481. [Ruediger Pluem]
 

Modified: httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml?rev=1051582&r1=1051581&r2=1051582&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml (original)
+++ httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml Tue Dec 21 17:52:43 2010
@@ -38,6 +38,7 @@
      [ -<strong>L</strong> <var>linkname</var> ]
      [ -<strong>f</strong> ]
      [ -<strong>v</strong> ]
+     [ -<strong>e</strong> ]
      <var>logfile</var>
      <var>rotationtime</var>|<var>filesize</var>(B|K|M|G) 
      [ <var>offset</var> ]</code></p>
@@ -80,6 +81,10 @@ will be respected.
 the result of the configuration parsing, and all file open and
 close actions.</dd>
 
+<dt><code>-e</code></dt>
+<dd>Echo logs through to stdout. Useful when logs need to be further
+processed in real time by a further tool in the chain.</dd>
+
 <dt><code><var>logfile</var></code></dt>
 
 <dd><p>The path plus basename of the logfile.  If <var>logfile</var>

Modified: httpd/httpd/trunk/support/rotatelogs.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=1051582&r1=1051581&r2=1051582&view=diff
==============================================================================
--- httpd/httpd/trunk/support/rotatelogs.c (original)
+++ httpd/httpd/trunk/support/rotatelogs.c Tue Dec 21 17:52:43 2010
@@ -87,6 +87,7 @@ struct rotate_config {
     int use_strftime;
     int force_open;
     int verbose;
+    int echo;
     const char *szLogRoot;
     int truncate;
     const char *linkfile;
@@ -116,7 +117,7 @@ static void usage(const char *argv0, con
         fprintf(stderr, "%s\n", reason);
     }
     fprintf(stderr,
-            "Usage: %s [-v] [-l] [-L linkname] [-f] [-t] <logfile> "
+            "Usage: %s [-v] [-l] [-L linkname] [-f] [-t] [-e] <logfile> "
             "{<rotation time in seconds>|<rotation size>(B|K|M|G)} "
             "[offset minutes from UTC]\n\n",
             argv0);
@@ -142,7 +143,8 @@ static void usage(const char *argv0, con
             "instead of rotated, and is useful where tail is used to\n"
             "process logs in real time.  If the -L option is specified, "
             "a hard link will be\nmade from the current log file to the "
-            "specified filename.\n");
+            "specified filename. In the case of the -e option, the log "
+            "will be echoed through to stdout for further processing.\n");
     exit(1);
 }
 
@@ -435,6 +437,7 @@ int main (int argc, const char * const a
     char buf[BUFSIZE];
     apr_size_t nRead, nWrite;
     apr_file_t *f_stdin;
+    apr_file_t *f_stdout;
     apr_getopt_t *opt;
     apr_status_t rv;
     char c;
@@ -451,6 +454,7 @@ int main (int argc, const char * const a
     config.use_strftime = 0;
     config.force_open = 0;
     config.verbose = 0;
+    config.echo = 0;
     status.pool = NULL;
     status.pfile = NULL;
     status.pfile_prev = NULL;
@@ -462,7 +466,7 @@ int main (int argc, const char * const a
 
     apr_pool_create(&status.pool, NULL);
     apr_getopt_init(&opt, status.pool, argc, argv);
-    while ((rv = apr_getopt(opt, "lL:ftv", &c, &opt_arg)) == APR_SUCCESS) {
+    while ((rv = apr_getopt(opt, "lL:ftve", &c, &opt_arg)) == APR_SUCCESS) {
         switch (c) {
         case 'l':
             config.use_localtime = 1;
@@ -479,6 +483,9 @@ int main (int argc, const char * const a
         case 'v':
             config.verbose = 1;
             break;
+        case 'e':
+            config.echo = 1;
+            break;
         }
     }
 
@@ -512,6 +519,11 @@ int main (int argc, const char * const a
         exit(1);
     }
 
+    if (apr_file_open_stdout(&f_stdout, status.pool) != APR_SUCCESS) {
+        fprintf(stderr, "Unable to open stdout\n");
+        exit(1);
+    }
+
     /*
      * Write out result of config parsing if verbose is set.
      */
@@ -575,6 +587,12 @@ int main (int argc, const char * const a
         else {
             status.nMessCount++;
         }
+        if (config.echo) {
+            if (apr_file_write_full(f_stdout, buf, nRead, &nWrite)) {
+                fprintf(stderr, "Unable to write to stdout\n");
+                exit(4);
+            }
+        }
     }
     /* Of course we never, but prevent compiler warnings */
     return 0;



Mime
View raw message