httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r733520 - in /httpd/httpd/trunk: CHANGES docs/man/rotatelogs.8 docs/manual/programs/rotatelogs.xml support/rotatelogs.c
Date Sun, 11 Jan 2009 21:26:13 GMT
Author: rjung
Date: Sun Jan 11 13:26:13 2009
New Revision: 733520

URL: http://svn.apache.org/viewvc?rev=733520&view=rev
Log:
rotatelogs: Add flag for verbose (debug) output.

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/docs/man/rotatelogs.8
    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=733520&r1=733519&r2=733520&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Sun Jan 11 13:26:13 2009
@@ -2,6 +2,8 @@
 Changes with Apache 2.3.2
 [ When backported to 2.2.x, remove entry from this file ]
 
+ *) rotatelogs: Add flag for verbose (debug) output. [Rainer Jung]
+
  *) rotatelogs: Allow to trigger log file rotation from outside
     using HUP and INT signals. PR 44427 [Rainer Jung]
 

Modified: httpd/httpd/trunk/docs/man/rotatelogs.8
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/man/rotatelogs.8?rev=733520&r1=733519&r2=733520&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/man/rotatelogs.8 (original)
+++ httpd/httpd/trunk/docs/man/rotatelogs.8 Sun Jan 11 13:26:13 2009
@@ -27,7 +27,7 @@
 .SH "SYNOPSIS"
  
 .PP
-\fBrotatelogs\fR [ -\fBl\fR ] [ -\fBf\fR ] \fIlogfile\fR \fIrotationtime\fR|\fIfilesize\fRM
[ \fIoffset\fR ]
+\fBrotatelogs\fR [ -\fBl\fR ] [ -\fBf\fR ] [ -\fBv\fR ] \fIlogfile\fR \fIrotationtime\fR|\fIfilesize\fRM
[ \fIoffset\fR ]
  
 
 .SH "SUMMARY"
@@ -46,6 +46,9 @@
 -f
 Causes the logfile to be opened immediately, as soon as rotatelogs starts, instead of waiting
for the first logfile entry to be read (for non-busy sites, there may be a substantial delay
between when the server is started and when the first request is handled, meaning that the
associated logfile does not "exist" until then, which causes problems from some automated
logging tools)  
 .TP
+-v
+Produce verbose output on STDERR\&. The output contains the result of the configuration
parsing, and all file open and close actions.
+.TP
 \fIlogfile\fR
 The path plus basename of the logfile\&. If \fIlogfile\fR includes any '%' characters,
it is treated as a format string for strftime(3)\&. Otherwise, the suffix \fI\&.nnnnnnnnnn\fR
is automatically added and is the time in seconds\&. Both formats compute the start time
from the beginning of the current period\&. For example, if a rotation time of 86400 is
specified, the hour, minute, and second fields created from the strftime(3) format will all
be zero, referring to the beginning of the current 24-hour period (midnight)\&.  
 .TP

Modified: httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml?rev=733520&r1=733519&r2=733520&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml (original)
+++ httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml Sun Jan 11 13:26:13 2009
@@ -39,6 +39,7 @@
      <p><code><strong>rotatelogs</strong>
      [ -<strong>l</strong> ]
      [ -<strong>f</strong> ]
+     [ -<strong>v</strong> ]
      <var>logfile</var>
      <var>rotationtime</var>|<var>filesize</var>M 
      [ <var>offset</var> ]</code></p>
@@ -64,6 +65,11 @@
 associated logfile does not "exist" until then, which
 causes problems from some automated logging tools)</dd>
 
+<dt><code>-v</code></dt>
+<dd>Produce verbose output on STDERR. The output contains
+the result of the configuration parsing, and all file open and
+close actions.</dd>
+
 <dt><code><var>logfile</var></code></dt>
 
 <dd>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=733520&r1=733519&r2=733520&view=diff
==============================================================================
--- httpd/httpd/trunk/support/rotatelogs.c (original)
+++ httpd/httpd/trunk/support/rotatelogs.c Sun Jan 11 13:26:13 2009
@@ -34,6 +34,8 @@
  * -f option added Feb, 2008. This causes rotatelog to open/create
  *    the logfile as soon as it's started, not as soon as it sees
  *    data.
+ *
+ * -v option added Feb, 2008. Verbose output of command line parsing.
  */
 
 
@@ -79,6 +81,15 @@
 #define ROTATE_SIZE     3
 #define ROTATE_FORCE    4
 
+static const char *ROTATE_REASONS[] = {
+    "None",
+    "Open a new file",
+    "Time interval expired",
+    "Maximum size reached",
+    "Forced rotation",
+    NULL
+};
+
 typedef struct rotate_config rotate_config_t;
 
 struct rotate_config {
@@ -88,6 +99,7 @@
     int use_localtime;
     int use_strftime;
     int force_open;
+    int verbose;
     const char *szLogRoot;
 };
 
@@ -116,7 +128,7 @@
         fprintf(stderr, "%s\n", reason);
     }
     fprintf(stderr,
-            "Usage: %s [-l] [-f] <logfile> "
+            "Usage: %s [-v] [-l] [-f] <logfile> "
             "{<rotation time in seconds>|<rotation size in megabytes>} "
             "[offset minutes from UTC]\n\n",
             argv0);
@@ -157,9 +169,16 @@
     return (int)apr_time_sec(tNow) + utc_offset;
 }
 
-static void closeFile(apr_pool_t *pool, apr_file_t *file)
+static void closeFile(rotate_config_t *config, apr_pool_t *pool, apr_file_t *file)
 {
     if (file != NULL) {
+        if (config->verbose) {
+            apr_finfo_t finfo;
+            apr_int32_t wanted = APR_FINFO_NAME;
+            if (apr_file_info_get(&finfo, wanted, file) == APR_SUCCESS) {
+                fprintf(stderr, "Closing file %s (%s)\n", finfo.name, finfo.fname);
+            }
+        }
         apr_file_close(file);
         if (pool) {
             apr_pool_destroy(pool);
@@ -167,6 +186,18 @@
     }
 }
 
+static void dumpConfig (rotate_config_t *config)
+{
+    fprintf(stderr, "Rotation time interval:      %12d\n", config->tRotation);
+    fprintf(stderr, "Rotation size interval:      %12d\n", config->sRotation);
+    fprintf(stderr, "Rotation time UTC offset:    %12d\n", config->utc_offset);
+    fprintf(stderr, "Rotation based on localtime: %12s\n", config->use_localtime ? "yes"
: "no");
+    fprintf(stderr, "Rotation file date pattern:  %12s\n", config->use_strftime ? "yes"
: "no");
+    fprintf(stderr, "Rotation file forced open:   %12s\n", config->force_open ? "yes"
: "no");
+    fprintf(stderr, "Rotation verbose:            %12s\n", config->verbose ? "yes" : "no");
+    fprintf(stderr, "Rotation file name: %21s\n", config->szLogRoot);
+}
+
 static void checkRotate(rotate_config_t *config, rotate_status_t *status)
 {
 
@@ -198,13 +229,17 @@
         exit(2);
     }
 
+    if (status->rotateReason != ROTATE_NONE && config->verbose) {
+        fprintf(stderr, "File rotation needed, reason: %s\n", ROTATE_REASONS[status->rotateReason]);
+    }
+
     /*
      * Let's close the file before immediately
      * if we got here via a signal.
      */
     if ((status->rotateReason != ROTATE_NONE) &&
         (status->checkReason != CHECK_LOG)) {
-        closeFile(status->pfile, status->nLogFD);
+        closeFile(config, status->pfile, status->nLogFD);
         status->nLogFD = NULL;
         status->pfile = NULL;
     }
@@ -253,6 +288,9 @@
         sprintf(status->filename, "%s.%010d", config->szLogRoot, tLogStart);
     }
     apr_pool_create(&status->pfile, status->pool);
+    if (config->verbose) {
+        fprintf(stderr, "Opening file %s\n", status->filename);
+    }
     rv = apr_file_open(&status->nLogFD, status->filename, APR_WRITE | APR_CREATE
| APR_APPEND,
                        APR_OS_DEFAULT, status->pfile);
     if (rv != APR_SUCCESS) {
@@ -287,7 +325,7 @@
         }
     }
     else {
-        closeFile(status->pfile_prev, status->nLogFDprev);
+        closeFile(config, status->pfile_prev, status->nLogFDprev);
         status->nLogFDprev = NULL;
         status->pfile_prev = NULL;
     }
@@ -346,6 +384,7 @@
     config.use_localtime = 0;
     config.use_strftime = 0;
     config.force_open = 0;
+    config.verbose = 0;
     status.pool = NULL;
     status.pfile = NULL;
     status.pfile_prev = NULL;
@@ -358,7 +397,7 @@
 
     apr_pool_create(&status.pool, NULL);
     apr_getopt_init(&opt, status.pool, argc, argv);
-    while ((rv = apr_getopt(opt, "lf", &c, &optarg)) == APR_SUCCESS) {
+    while ((rv = apr_getopt(opt, "lfv", &c, &optarg)) == APR_SUCCESS) {
         switch (c) {
         case 'l':
             config.use_localtime = 1;
@@ -366,6 +405,9 @@
         case 'f':
             config.force_open = 1;
             break;
+        case 'v':
+            config.verbose = 1;
+            break;
         }
     }
 
@@ -410,6 +452,13 @@
     }
 
     /*
+     * Write out result of config parsing if verbose is set.
+     */
+    if (config.verbose) {
+        dumpConfig(&config);
+    }
+
+    /*
      * Immediately open the logfile as we start, if we were forced
      * to do so via '-f'.
      */



Mime
View raw message