]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
rotatelogs: Add flag for verbose (debug) output.
authorRainer Jung <rjung@apache.org>
Sun, 11 Jan 2009 21:26:13 +0000 (21:26 +0000)
committerRainer Jung <rjung@apache.org>
Sun, 11 Jan 2009 21:26:13 +0000 (21:26 +0000)
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@733520 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/man/rotatelogs.8
docs/manual/programs/rotatelogs.xml
support/rotatelogs.c

diff --git a/CHANGES b/CHANGES
index 464c8a3263dee1ae3723b384704eafa674b77076..58450a721d3d7b6859dbcc69716b73f23281214c 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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]
 
index ee89afd2c63185fe3080fa9e6cfe7b7e22646428..b3a9888506c7ea6999a21098665e799cb1caf216 100644 (file)
@@ -27,7 +27,7 @@ rotatelogs \- Piped logging program to rotate Apache logs
 .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 @@ Causes the use of local time rather than GMT as the base for the interval or for
 -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
index 7d2bf30ca0a275c714fd35fe908ff8ff683e5d40..df2bd5bd2d698bebdb92b114213ca0ba27235e49 100644 (file)
@@ -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 @@ 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)</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>
index ab0dcc89496f9eb22add55c8a0f2a9e104a5258c..8e602880745d55866596c8013846e233fe3d8850 100644 (file)
@@ -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.
  */
 
 
 #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 @@ struct rotate_config {
     int use_localtime;
     int use_strftime;
     int force_open;
+    int verbose;
     const char *szLogRoot;
 };
 
@@ -116,7 +128,7 @@ static void usage(const char *argv0, const char *reason)
         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 @@ static int get_now(rotate_config_t *config)
     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 closeFile(apr_pool_t *pool, apr_file_t *file)
     }
 }
 
+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 @@ static void checkRotate(rotate_config_t *config, rotate_status_t *status)
         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 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
         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 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
         }
     }
     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 @@ int main (int argc, const char * const argv[])
     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 @@ int main (int argc, const char * const argv[])
 
     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 @@ int main (int argc, const char * const argv[])
         case 'f':
             config.force_open = 1;
             break;
+        case 'v':
+            config.verbose = 1;
+            break;
         }
     }
 
@@ -409,6 +451,13 @@ int main (int argc, const char * const argv[])
         exit(1);
     }
 
+    /*
+     * 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'.