Return-Path: X-Original-To: apmail-httpd-cvs-archive@www.apache.org Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4841B1050E for ; Fri, 7 Jun 2013 01:51:56 +0000 (UTC) Received: (qmail 34155 invoked by uid 500); 7 Jun 2013 01:51:55 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 34104 invoked by uid 500); 7 Jun 2013 01:51:55 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 34097 invoked by uid 99); 7 Jun 2013 01:51:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Jun 2013 01:51:55 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Jun 2013 01:51:52 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D2ACA2388847; Fri, 7 Jun 2013 01:51:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1490493 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/rotatelogs.xml support/rotatelogs.c Date: Fri, 07 Jun 2013 01:51:31 -0000 To: cvs@httpd.apache.org From: covener@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130607015131.D2ACA2388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: covener Date: Fri Jun 7 01:51:31 2013 New Revision: 1490493 URL: http://svn.apache.org/r1490493 Log: rotatelogs: add -n number-of-files option to roate through a number of fixed-name logfiles. 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=1490493&r1=1490492&r2=1490493&view=diff ============================================================================== --- httpd/httpd/trunk/CHANGES [utf-8] (original) +++ httpd/httpd/trunk/CHANGES [utf-8] Fri Jun 7 01:51:31 2013 @@ -1,5 +1,7 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) rotatelogs: add -n number-of-files option to roate through a number + of fixed-name logfiles. [Eric Covener] *) mod_lua: If a LuaMapHandler doesn't return any value, log a warning and treat it as apache2.OK. [Eric Covener] Modified: httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml?rev=1490493&r1=1490492&r2=1490493&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml (original) +++ httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml Fri Jun 7 01:51:31 2013 @@ -41,6 +41,7 @@ [ -v ] [ -e ] [ -c ] + [ -n number-of-files ] logfile rotationtime|filesize(B|K|M|G) [ offset ]

@@ -102,6 +103,11 @@ processed in real time by a further tool
-c
Create log file for each interval, even if empty.
+
-n number-of-files
+
Use a circular list of filenames without timestamps. +With -n 3, the series of log files opened would be +"logfile", "logfile.1", "logfile.2", then overwriting "logfile".
+
logfile

The path plus basename of the logfile. If logfile Modified: httpd/httpd/trunk/support/rotatelogs.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=1490493&r1=1490492&r2=1490493&view=diff ============================================================================== --- httpd/httpd/trunk/support/rotatelogs.c (original) +++ httpd/httpd/trunk/support/rotatelogs.c Fri Jun 7 01:51:31 2013 @@ -70,6 +70,7 @@ struct rotate_config { #if APR_FILES_AS_SOCKETS int create_empty; #endif + int num_files; }; typedef struct rotate_status rotate_status_t; @@ -89,6 +90,7 @@ struct rotate_status { int rotateReason; int tLogEnd; int nMessCount; + int fileNum; }; static rotate_config_t config; @@ -101,9 +103,9 @@ static void usage(const char *argv0, con } fprintf(stderr, #if APR_FILES_AS_SOCKETS - "Usage: %s [-v] [-l] [-L linkname] [-p prog] [-f] [-t] [-e] [-c] " + "Usage: %s [-v] [-l] [-L linkname] [-p prog] [-f] [-t] [-e] [-c] [-n number] " #else - "Usage: %s [-v] [-l] [-L linkname] [-p prog] [-f] [-t] [-e] " + "Usage: %s [-v] [-l] [-L linkname] [-p prog] [-f] [-t] [-e] [-n number] " #endif "{|(B|K|M|G)} " "[offset minutes from UTC]\n\n", @@ -362,6 +364,7 @@ static void doRotate(rotate_config_t *co int tLogStart; apr_status_t rv; struct logfile newlog; + int thisLogNum = -1; status->rotateReason = ROTATE_NONE; @@ -395,6 +398,16 @@ static void doRotate(rotate_config_t *co if (config->truncate) { apr_snprintf(newlog.name, sizeof(newlog.name), "%s", config->szLogRoot); } + else if (config->num_files > 0) { + if (status->fileNum == -1 || status->fileNum == (config->num_files - 1)) { + thisLogNum = 0; + apr_snprintf(newlog.name, sizeof(newlog.name), "%s", config->szLogRoot); + } + else { + thisLogNum = status->fileNum + 1; + apr_snprintf(newlog.name, sizeof(newlog.name), "%s.%d", config->szLogRoot, thisLogNum); + } + } else { apr_snprintf(newlog.name, sizeof(newlog.name), "%s.%010d", config->szLogRoot, tLogStart); @@ -405,11 +418,13 @@ static void doRotate(rotate_config_t *co fprintf(stderr, "Opening file %s\n", newlog.name); } rv = apr_file_open(&newlog.fd, newlog.name, APR_WRITE | APR_CREATE | APR_APPEND - | (config->truncate ? APR_TRUNCATE : 0), APR_OS_DEFAULT, newlog.pool); + | (config->truncate || (config->num_files > 0) ? APR_TRUNCATE : 0), + APR_OS_DEFAULT, newlog.pool); if (rv == APR_SUCCESS) { /* Handle post-rotate processing. */ post_rotate(newlog.pool, &newlog, config, status); + status->fileNum = thisLogNum; /* Close out old (previously 'current') logfile, if any. */ if (status->current.fd) { close_logfile(config, &status->current); @@ -529,9 +544,9 @@ int main (int argc, const char * const a apr_pool_create(&status.pool, NULL); apr_getopt_init(&opt, status.pool, argc, argv); #if APR_FILES_AS_SOCKETS - while ((rv = apr_getopt(opt, "lL:p:ftvec", &c, &opt_arg)) == APR_SUCCESS) { + while ((rv = apr_getopt(opt, "lL:p:ftvecn:", &c, &opt_arg)) == APR_SUCCESS) { #else - while ((rv = apr_getopt(opt, "lL:p:ftve", &c, &opt_arg)) == APR_SUCCESS) { + while ((rv = apr_getopt(opt, "lL:p:ftven:", &c, &opt_arg)) == APR_SUCCESS) { #endif switch (c) { case 'l': @@ -560,6 +575,10 @@ int main (int argc, const char * const a config.create_empty = 1; break; #endif + case 'n': + config.num_files = atoi(opt_arg); + status.fileNum = -1; + break; } } @@ -588,6 +607,16 @@ int main (int argc, const char * const a config.use_strftime = (strchr(config.szLogRoot, '%') != NULL); + if (config.use_strftime && config.num_files > 0) { + fprintf(stderr, "Cannot use -n with %% in filename\n"); + exit(1); + } + + if (status.fileNum == -1 && config.num_files < 1) { + fprintf(stderr, "Invalid -n argument\n"); + exit(1); + } + if (apr_file_open_stdin(&f_stdin, status.pool) != APR_SUCCESS) { fprintf(stderr, "Unable to open stdin\n"); exit(1);