From a5f4ee184566a4f55c2c967749cc4cde43fffe19 Mon Sep 17 00:00:00 2001
From: Stefan Fritsch
Date: Sun, 6 Jun 2010 17:09:43 +0000
Subject: [PATCH] Replace RewriteLog/RewriteLogLevel with trace log levels
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@951903 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/mod/mod_rewrite.xml | 96 ++++-------------
docs/manual/rewrite/intro.xml | 16 ++-
modules/mappers/mod_rewrite.c | 181 +++-----------------------------
3 files changed, 38 insertions(+), 255 deletions(-)
diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml
index 159fc61631..08c60ae249 100644
--- a/docs/manual/mod/mod_rewrite.xml
+++ b/docs/manual/mod/mod_rewrite.xml
@@ -53,6 +53,26 @@ URLs on the fly
detailed mod_rewrite documentation.
+Logging
+
+ mod_rewrite offers detailed logging of its actions
+ at the trace1
to trace8
log levels. The
+ log level can be set specifically for mod_rewrite
+ using the LogLevel directive: Up to
+ level debug
, no actions are logged, while trace8
+ means that practically all actions are logged.
+
+
+ Using a high trace log level for mod_rewrite
+ will slow down your Apache HTTP Server dramatically! Use a log
+ level than trace2
only for debugging!
+
+
+ Example
+ LogLevel rewrite:trace3
+
+
+
RewriteEngine
@@ -125,82 +145,6 @@ later
-
-RewriteLog
-Sets the name of the file used for logging rewrite engine
-processing
-RewriteLog file-path
-server configvirtual host
-
-
-
- The RewriteLog directive sets the name
- of the file to which the server logs any rewriting actions it
- performs. If the name does not begin with a slash
- ('/
') then it is assumed to be relative to the
- Server Root. The directive should occur only once per
- server config.
-
- To disable the logging of
- rewriting actions it is not recommended to set
- Filename to /dev/null
, because
- although the rewriting engine does not then output to a
- logfile it still creates the logfile output internally.
- This will slow down the server with no advantage
- to the administrator! To disable logging either
- remove or comment out the RewriteLog
- directive or use RewriteLogLevel 0
!
-
-
-Security
-
-See the Apache HTTP Server Security Tips
-document for details on how your security could be compromised if the
-directory where logfiles are stored is writable by anyone other than
-the user that starts the server.
-
-
-Example
-RewriteLog "/usr/local/var/apache/logs/rewrite.log"
-
-
-
-
-
-
-
-RewriteLogLevel
-Sets the verbosity of the log file used by the rewrite
-engine
-RewriteLogLevel Level
-RewriteLogLevel 0
-server configvirtual host
-
-
-
- The RewriteLogLevel directive sets the
- verbosity level of the rewriting logfile. The default level 0
- means no logging, while 9 or more means that practically all
- actions are logged.
-
- To disable the logging of rewriting actions simply set
- Level to 0. This disables all rewrite action
- logs.
-
- Using a high value for
- Level will slow down your Apache HTTP Server
- dramatically! Use the rewriting logfile at a
- Level greater than 2 only for debugging!
-
-
-Example
-RewriteLogLevel 3
-
-
-
-
-
-
RewriteMap
Defines a mapping function for key-lookup
diff --git a/docs/manual/rewrite/intro.xml b/docs/manual/rewrite/intro.xml
index 01d0ceb0a8..3524f769a8 100644
--- a/docs/manual/rewrite/intro.xml
+++ b/docs/manual/rewrite/intro.xml
@@ -63,16 +63,12 @@ on mapping URLs to the
filesystem.
Finally, before proceeding, be sure to configure
-the RewriteLog. Although
-this log file can give an overwhelming amount of information, it is
-indispensable in debugging problems with mod_rewrite
-configuration, since it will tell you exactly how each rule is
-processed.
-
-
-The RewriteLog directive cannot be used in .htaccess files, but can
-only be set in the main server configuration file.
-
+mod_rewrite's log level to one of the trace levels using
+the LogLevel directive. Although this
+can give an overwhelming amount of information, it is indispensable in
+debugging problems with mod_rewrite configuration, since
+it will tell you exactly how each rule is processed.
+
Regular Expressions
diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c
index fd9771a9df..50181c3717 100644
--- a/modules/mappers/mod_rewrite.c
+++ b/modules/mappers/mod_rewrite.c
@@ -111,6 +111,15 @@ static void (*dbd_prepare)(server_rec*, const char*, const char*) = NULL;
* DO NOT USE THIS OPTION FOR PUBLIC BINARY RELEASES. Otherwise YOU are
* responsible for answering all the mod_rewrite questions out there.
*/
+/* If logging is limited to APLOG_DEBUG or lower, disable rewrite log, too */
+#ifdef APLOG_MAX_LOGLEVEL
+#if APLOG_MAX_LOGLEVEL < APLOG_TRACE1
+#ifndef REWRITELOG_DISABLED
+#define REWRITELOG_DISABLED
+#endif
+#endif
+#endif
+
#ifndef REWRITELOG_DISABLED
#define rewritelog(x) do_rewritelog x
@@ -287,11 +296,6 @@ typedef struct {
typedef struct {
int state; /* the RewriteEngine state */
int options; /* the RewriteOption state */
-#ifndef REWRITELOG_DISABLED
- const char *rewritelogfile; /* the RewriteLog filename */
- apr_file_t *rewritelogfp; /* the RewriteLog open filepointer */
- int rewriteloglevel; /* the RewriteLog level of verbosity */
-#endif
apr_hash_t *rewritemaps; /* the RewriteMap entries */
apr_array_header_t *rewriteconds; /* the RewriteCond entries (temp.) */
apr_array_header_t *rewriterules; /* the RewriteRule entries */
@@ -397,80 +401,6 @@ static char *escape_uri(apr_pool_t *p, const char *path);
*/
#ifndef REWRITELOG_DISABLED
-static char *current_logtime(request_rec *r)
-{
- apr_time_exp_t t;
- char tstr[80];
- apr_size_t len;
-
- apr_time_exp_lt(&t, apr_time_now());
-
- apr_strftime(tstr, &len, sizeof(tstr), "[%d/%b/%Y:%H:%M:%S ", &t);
- apr_snprintf(tstr+len, sizeof(tstr)-len, "%c%.2d%.2d]",
- t.tm_gmtoff < 0 ? '-' : '+',
- t.tm_gmtoff / (60*60), t.tm_gmtoff % (60*60));
-
- return apr_pstrdup(r->pool, tstr);
-}
-
-static int open_rewritelog(server_rec *s, apr_pool_t *p)
-{
- rewrite_server_conf *conf;
- const char *fname;
-
- conf = ap_get_module_config(s->module_config, &rewrite_module);
-
- /* - no logfile configured
- * - logfilename empty
- * - virtual log shared w/ main server
- */
- if (!conf->rewritelogfile || !*conf->rewritelogfile || conf->rewritelogfp) {
- return 1;
- }
-
- if (*conf->rewritelogfile == '|') {
- piped_log *pl;
-
- fname = ap_server_root_relative(p, conf->rewritelogfile+1);
- if (!fname) {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,
- "mod_rewrite: Invalid RewriteLog "
- "path %s", conf->rewritelogfile+1);
- return 0;
- }
-
- if ((pl = ap_open_piped_log(p, fname)) == NULL) {
- ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
- "mod_rewrite: could not open reliable pipe "
- "to RewriteLog filter %s", fname);
- return 0;
- }
- conf->rewritelogfp = ap_piped_log_write_fd(pl);
- }
- else {
- apr_status_t rc;
-
- fname = ap_server_root_relative(p, conf->rewritelogfile);
- if (!fname) {
- ap_log_error(APLOG_MARK, APLOG_ERR, APR_EBADPATH, s,
- "mod_rewrite: Invalid RewriteLog "
- "path %s", conf->rewritelogfile);
- return 0;
- }
-
- if ((rc = apr_file_open(&conf->rewritelogfp, fname,
- REWRITELOG_FLAGS, REWRITELOG_MODE, p))
- != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rc, s,
- "mod_rewrite: could not open RewriteLog "
- "file %s", fname);
- return 0;
- }
- }
-
- return 1;
-}
-
static void do_rewritelog(request_rec *r, int level, char *perdir,
const char *fmt, ...)
__attribute__((format(printf,4,5)));
@@ -478,21 +408,12 @@ static void do_rewritelog(request_rec *r, int level, char *perdir,
static void do_rewritelog(request_rec *r, int level, char *perdir,
const char *fmt, ...)
{
- rewrite_server_conf *conf;
char *logline, *text;
const char *rhost, *rname;
- apr_size_t nbytes;
int redir;
request_rec *req;
va_list ap;
- conf = ap_get_module_config(r->server->module_config, &rewrite_module);
-
- if ((!conf->rewritelogfp || level > conf->rewriteloglevel) &&
- !AP_REWRITE_LOG_ENABLED()) {
- return;
- }
-
rhost = ap_get_remote_host(r->connection, r->per_dir_config,
REMOTE_NOLOOKUP, NULL);
rname = ap_get_remote_logname(r);
@@ -505,19 +426,17 @@ static void do_rewritelog(request_rec *r, int level, char *perdir,
text = apr_pvsprintf(r->pool, fmt, ap);
va_end(ap);
- logline = apr_psprintf(r->pool, "%s %s %s %s [%s/sid#%pp][rid#%pp/%s%s%s] "
- "(%d) %s%s%s%s" APR_EOL_STR,
+ logline = apr_psprintf(r->pool, "%s %s %s [%s/sid#%pp][rid#%pp/%s%s%s] "
+ "%s%s%s%s" APR_EOL_STR,
rhost ? rhost : "UNKNOWN-HOST",
rname ? rname : "-",
r->user ? (*r->user ? r->user : "\"\"") : "-",
- current_logtime(r),
ap_get_server_name(r),
(void *)(r->server),
(void *)r,
r->main ? "subreq" : "initial",
redir ? "/redir#" : "",
redir ? apr_itoa(r->pool, redir) : "",
- level,
perdir ? "[perdir " : "",
perdir ? perdir : "",
perdir ? "] ": "",
@@ -525,11 +444,7 @@ static void do_rewritelog(request_rec *r, int level, char *perdir,
AP_REWRITE_LOG((uintptr_t)r, level, r->main ? 0 : 1, (char *)ap_get_server_name(r), logline);
- if (!conf->rewritelogfp || level > conf->rewriteloglevel)
- return;
-
- nbytes = strlen(logline);
- apr_file_write(conf->rewritelogfp, logline, &nbytes);
+ ap_log_rerror(APLOG_MARK, APLOG_DEBUG + level, 0, r, logline);
return;
}
@@ -2772,11 +2687,6 @@ static void *config_server_create(apr_pool_t *p, server_rec *s)
a->state = ENGINE_DISABLED;
a->options = OPTION_NONE;
-#ifndef REWRITELOG_DISABLED
- a->rewritelogfile = NULL;
- a->rewritelogfp = NULL;
- a->rewriteloglevel = 0;
-#endif
a->rewritemaps = apr_hash_make(p);
a->rewriteconds = apr_array_make(p, 2, sizeof(rewritecond_entry));
a->rewriterules = apr_array_make(p, 2, sizeof(rewriterule_entry));
@@ -2803,17 +2713,6 @@ static void *config_server_merge(apr_pool_t *p, void *basev, void *overridesv)
* local directives override
* and anything else is inherited
*/
-#ifndef REWRITELOG_DISABLED
- a->rewriteloglevel = overrides->rewriteloglevel != 0
- ? overrides->rewriteloglevel
- : base->rewriteloglevel;
- a->rewritelogfile = overrides->rewritelogfile != NULL
- ? overrides->rewritelogfile
- : base->rewritelogfile;
- a->rewritelogfp = overrides->rewritelogfp != NULL
- ? overrides->rewritelogfp
- : base->rewritelogfp;
-#endif
a->rewritemaps = apr_hash_overlay(p, overrides->rewritemaps,
base->rewritemaps);
a->rewriteconds = apr_array_append(p, overrides->rewriteconds,
@@ -2826,11 +2725,6 @@ static void *config_server_merge(apr_pool_t *p, void *basev, void *overridesv)
* local directives override
* and anything else gets defaults
*/
-#ifndef REWRITELOG_DISABLED
- a->rewriteloglevel = overrides->rewriteloglevel;
- a->rewritelogfile = overrides->rewritelogfile;
- a->rewritelogfp = overrides->rewritelogfp;
-#endif
a->rewritemaps = overrides->rewritemaps;
a->rewriteconds = overrides->rewriteconds;
a->rewriterules = overrides->rewriterules;
@@ -2955,29 +2849,6 @@ static const char *cmd_rewriteoptions(cmd_parms *cmd,
return NULL;
}
-#ifndef REWRITELOG_DISABLED
-static const char *cmd_rewritelog(cmd_parms *cmd, void *dconf, const char *a1)
-{
- rewrite_server_conf *sconf;
-
- sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module);
- sconf->rewritelogfile = a1;
-
- return NULL;
-}
-
-static const char *cmd_rewriteloglevel(cmd_parms *cmd, void *dconf,
- const char *a1)
-{
- rewrite_server_conf *sconf;
-
- sconf = ap_get_module_config(cmd->server->module_config, &rewrite_module);
- sconf->rewriteloglevel = atoi(a1);
-
- return NULL;
-}
-#endif /* rewritelog */
-
static const char *cmd_rewritemap(cmd_parms *cmd, void *dconf, const char *a1,
const char *a2)
{
@@ -4289,12 +4160,6 @@ static int post_config(apr_pool_t *p,
* - open the RewriteMap prg:xxx programs
*/
for (; s; s = s->next) {
-#ifndef REWRITELOG_DISABLED
- if (!open_rewritelog(s, p)) {
- return HTTP_INTERNAL_SERVER_ERROR;
- }
-#endif
-
if (!first_time) {
if (run_rewritemap_programs(s, p) != APR_SUCCESS) {
return HTTP_INTERNAL_SERVER_ERROR;
@@ -4963,16 +4828,6 @@ static int handler_redirect(request_rec *r)
* +-------------------------------------------------------+
*/
-#ifdef REWRITELOG_DISABLED
-static const char *fake_rewritelog(cmd_parms *cmd, void *dummy, const char *a1)
-{
- return "RewriteLog and RewriteLogLevel are not supported by this build "
- "of mod_rewrite because it was compiled using the "
- "-DREWRITELOG_DISABLED compiler option. You have to recompile "
- "mod_rewrite WITHOUT this option in order to use the rewrite log.";
-}
-#endif
-
static const command_rec command_table[] = {
AP_INIT_FLAG( "RewriteEngine", cmd_rewriteengine, NULL, OR_FILEINFO,
"On or Off to enable or disable (default) the whole "
@@ -4987,18 +4842,6 @@ static const command_rec command_table[] = {
"an URL-applied regexp-pattern and a substitution URL"),
AP_INIT_TAKE2( "RewriteMap", cmd_rewritemap, NULL, RSRC_CONF,
"a mapname and a filename"),
-#ifndef REWRITELOG_DISABLED
- AP_INIT_TAKE1( "RewriteLog", cmd_rewritelog, NULL, RSRC_CONF,
- "the filename of the rewriting logfile"),
- AP_INIT_TAKE1( "RewriteLogLevel", cmd_rewriteloglevel, NULL, RSRC_CONF,
- "the level of the rewriting logfile verbosity "
- "(0=none, 1=std, .., 9=max)"),
-#else
- AP_INIT_TAKE1( "RewriteLog", fake_rewritelog, NULL, RSRC_CONF,
- "[DISABLED] the filename of the rewriting logfile"),
- AP_INIT_TAKE1( "RewriteLogLevel", fake_rewritelog, NULL, RSRC_CONF,
- "[DISABLED] the level of the rewriting logfile verbosity"),
-#endif
{ NULL }
};
--
2.50.1