From: Rainer Jung Date: Sun, 11 Jan 2009 21:26:13 +0000 (+0000) Subject: rotatelogs: Add flag for verbose (debug) output. X-Git-Tag: 2.3.2~181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fd9690630283497232dba036aeb20aa884d6ce79;p=thirdparty%2Fapache%2Fhttpd.git rotatelogs: Add flag for verbose (debug) output. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@733520 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 464c8a3263d..58450a721d3 100644 --- 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] diff --git a/docs/man/rotatelogs.8 b/docs/man/rotatelogs.8 index ee89afd2c63..b3a9888506c 100644 --- a/docs/man/rotatelogs.8 +++ b/docs/man/rotatelogs.8 @@ -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 diff --git a/docs/manual/programs/rotatelogs.xml b/docs/manual/programs/rotatelogs.xml index 7d2bf30ca0a..df2bd5bd2d6 100644 --- a/docs/manual/programs/rotatelogs.xml +++ b/docs/manual/programs/rotatelogs.xml @@ -39,6 +39,7 @@

rotatelogs [ -l ] [ -f ] + [ -v ] logfile rotationtime|filesizeM [ offset ]

@@ -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) +
-v
+
Produce verbose output on STDERR. The output contains +the result of the configuration parsing, and all file open and +close actions.
+
logfile
The path plus basename of the logfile. If logfile diff --git a/support/rotatelogs.c b/support/rotatelogs.c index ab0dcc89496..8e602880745 100644 --- a/support/rotatelogs.c +++ b/support/rotatelogs.c @@ -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 @@ 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] " + "Usage: %s [-v] [-l] [-f] " "{|} " "[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'.