You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by sf...@apache.org on 2010/06/06 19:09:44 UTC

svn commit: r951903 - in /httpd/httpd/trunk: docs/manual/mod/mod_rewrite.xml docs/manual/rewrite/intro.xml modules/mappers/mod_rewrite.c

Author: sf
Date: Sun Jun  6 17:09:43 2010
New Revision: 951903

URL: http://svn.apache.org/viewvc?rev=951903&view=rev
Log:
Replace RewriteLog/RewriteLogLevel with trace log levels

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml
    httpd/httpd/trunk/docs/manual/rewrite/intro.xml
    httpd/httpd/trunk/modules/mappers/mod_rewrite.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml?rev=951903&r1=951902&r2=951903&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_rewrite.xml Sun Jun  6 17:09:43 2010
@@ -53,6 +53,26 @@ URLs on the fly</description>
       <a href="../rewrite/">detailed mod_rewrite documentation</a>.</p>
 </summary>
 
+<section><title>Logging</title>
+
+    <p><module>mod_rewrite</module> offers detailed logging of its actions
+    at the <code>trace1</code> to <code>trace8</code> log levels. The
+    log level can be set specifically for <module>mod_rewrite</module>
+    using the <directive module="core">LogLevel</directive> directive: Up to
+    level <code>debug</code>, no actions are logged, while <code>trace8</code>
+    means that practically all actions are logged.</p>
+
+    <note>
+      Using a high trace log level for <module>mod_rewrite</module>
+      will slow down your Apache HTTP Server dramatically! Use a log
+      level than <code>trace2</code> only for debugging!
+    </note>
+
+    <example><title>Example</title>
+      LogLevel rewrite:trace3
+    </example>
+
+</section>
 
 <directivesynopsis>
 <name>RewriteEngine</name>
@@ -126,82 +146,6 @@ later</compatibility>
 </directivesynopsis>
 
 <directivesynopsis>
-<name>RewriteLog</name>
-<description>Sets the name of the file used for logging rewrite engine
-processing</description>
-<syntax>RewriteLog <em>file-path</em></syntax>
-<contextlist><context>server config</context><context>virtual host</context>
-</contextlist>
-
-<usage>
-      <p>The <directive>RewriteLog</directive> 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
-      ('<code>/</code>') then it is assumed to be relative to the
-      <em>Server Root</em>. The directive should occur only once per
-      server config.</p>
-
-<note>    To disable the logging of
-          rewriting actions it is not recommended to set
-          <em>Filename</em> to <code>/dev/null</code>, because
-          although the rewriting engine does not then output to a
-          logfile it still creates the logfile output internally.
-          <strong>This will slow down the server with no advantage
-          to the administrator!</strong> To disable logging either
-          remove or comment out the <directive>RewriteLog</directive>
-          directive or use <code>RewriteLogLevel 0</code>!
-</note>
-
-<note type="securitywarning"><title>Security</title>
-
-See the <a href="../misc/security_tips.html">Apache HTTP Server Security Tips</a>
-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.
-</note>
-
-<example><title>Example</title>
-RewriteLog "/usr/local/var/apache/logs/rewrite.log"
-</example>
-
-</usage>
-
-</directivesynopsis>
-
-<directivesynopsis>
-<name>RewriteLogLevel</name>
-<description>Sets the verbosity of the log file used by the rewrite
-engine</description>
-<syntax>RewriteLogLevel <em>Level</em></syntax>
-<default>RewriteLogLevel 0</default>
-<contextlist><context>server config</context><context>virtual host</context>
-</contextlist>
-
-<usage>
-      <p>The <directive>RewriteLogLevel</directive> 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.</p>
-
-      <p>To disable the logging of rewriting actions simply set
-      <em>Level</em> to 0. This disables all rewrite action
-      logs.</p>
-
-<note> Using a high value for
-          <em>Level</em> will slow down your Apache HTTP Server
-          dramatically! Use the rewriting logfile at a
-          <em>Level</em> greater than 2 only for debugging!
-</note>
-
-<example><title>Example</title>
-RewriteLogLevel 3
-</example>
-
-</usage>
-
-</directivesynopsis>
-
-<directivesynopsis>
 <name>RewriteMap</name>
 <description>Defines a mapping function for key-lookup</description>
 <syntax>RewriteMap <em>MapName</em> <em>MapType</em>:<em>MapSource</em>

Modified: httpd/httpd/trunk/docs/manual/rewrite/intro.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/intro.xml?rev=951903&r1=951902&r2=951903&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/rewrite/intro.xml (original)
+++ httpd/httpd/trunk/docs/manual/rewrite/intro.xml Sun Jun  6 17:09:43 2010
@@ -63,16 +63,12 @@ on <a href="../urlmapping.html">mapping 
 filesystem</a>.</p>
 
 <p>Finally, before proceeding, be sure to configure
-the <directive module="mod_rewrite">RewriteLog</directive>. Although
-this log file can give an overwhelming amount of information, it is
-indispensable in debugging problems with <module>mod_rewrite</module>
-configuration, since it will tell you exactly how each rule is
-processed.</p>
-
-<note>
-<p>The RewriteLog directive cannot be used in .htaccess files, but can
-only be set in the main server configuration file.</p>
-</note>
+<module>mod_rewrite</module>'s log level to one of the trace levels using
+the <directive module="core">LogLevel</directive> directive. Although this
+can give an overwhelming amount of information, it is indispensable in
+debugging problems with <module>mod_rewrite</module> configuration, since
+it will tell you exactly how each rule is processed.</p>
+
 </section>
 
 <section id="regex"><title>Regular Expressions</title>

Modified: httpd/httpd/trunk/modules/mappers/mod_rewrite.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_rewrite.c?rev=951903&r1=951902&r2=951903&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_rewrite.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_rewrite.c Sun Jun  6 17:09:43 2010
@@ -111,6 +111,15 @@ static void (*dbd_prepare)(server_rec*, 
  * 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, c
  */
 
 #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
 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
     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
 
     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_po
 
     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_poo
          *  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_poo
          *  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(cm
     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 
  * +-------------------------------------------------------+
  */
 
-#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 }
 };