httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From humbed...@apache.org
Subject svn commit: r1519277 - in /httpd/httpd/trunk: docs/manual/mod/mod_lua.xml modules/lua/mod_lua.c
Date Sun, 01 Sep 2013 15:10:33 GMT
Author: humbedooh
Date: Sun Sep  1 15:10:32 2013
New Revision: 1519277

URL: http://svn.apache.org/r1519277
Log:
Adding a simple logging hook for mod_lua, which allows users to create their own logs or bypass
the generic logging on a per-request basis.

Modified:
    httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
    httpd/httpd/trunk/modules/lua/mod_lua.c

Modified: httpd/httpd/trunk/docs/manual/mod/mod_lua.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/mod/mod_lua.xml?rev=1519277&r1=1519276&r2=1519277&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/mod/mod_lua.xml (original)
+++ httpd/httpd/trunk/docs/manual/mod/mod_lua.xml Sun Sep  1 15:10:32 2013
@@ -269,9 +269,10 @@ performing access control, or setting mi
     </tr>
     <tr>
         <td>Logging</td>
-        <td>(none)</td>
+        <td><directive module="mod_lua">LuaHookLog</directive></td>
         <td>Once a request has been handled, it enters several logging phases, 
-            which logs the request in either the error or access log</td>
+            which logs the request in either the error or access log. Mod_lua
+            is able to hook into the start of this and control logging output.</td>
     </tr>
 
 </table>
@@ -1454,6 +1455,55 @@ processing</description>
 </directivesynopsis>
 
 <directivesynopsis>
+<name>LuaHookLog</name>
+<description>Provide a hook for the access log phase of a request
+processing</description>
+<syntax>LuaHookLog  /path/to/lua/script.lua log_function_name</syntax>
+<contextlist><context>server config</context><context>virtual host</context>
+<context>directory</context><context>.htaccess</context>
+</contextlist>
+<override>All</override>
+<usage>
+<p>
+    This simple logging hook allows you to run a function when httpd enters the 
+    logging phase of a request. With it, you can append data to your own logs, 
+    manipulate data before the regular log is written, or prevent a log entry 
+    from being created. To prevent the usual logging from happening, simply return
+    <code>apache2.DONE</code> in your logging handler, otherwise return 
+    <code>apache2.OK</code> to tell httpd to log as normal.
+</p>
+<p>Example:</p>
+<highlight language="config">
+LuaHookLog /path/to/script.lua logger
+</highlight>
+<highlight language="lua">
+-- /path/to/script.lua --
+function logger(r)
+    -- flip a coin:
+    -- If 1, then we write to our own Lua log and tell httpd not to log
+    -- in the main log.
+    -- If 2, then we just sanitize the output a bit and tell httpd to 
+    -- log the sanitized bits.
+
+    if math.random(1,2) == 1 then
+        -- Log stuff ourselves and don't log in the regular log
+        local f = io.open("/foo/secret.log", "a")
+        if f then
+            f:write("Something secret happened at " .. r.uri .. "\n")
+            f:close()
+        end
+        return apache2.DONE -- Tell httpd not to use the regular logging functions
+    else
+        r.uri = r.uri:gsub("somesecretstuff", "") -- sanitize the URI
+        return apache2.OK -- tell httpd to log it.
+    end
+end
+</highlight>
+</usage>
+</directivesynopsis>
+
+
+<directivesynopsis>
 <name>LuaHookMapToStorage</name>
 <description>Provide a hook for the map_to_storage phase of request processing</description>
 <syntax>LuaHookMapToStorage  /path/to/lua/script.lua hook_function_name</syntax>

Modified: httpd/httpd/trunk/modules/lua/mod_lua.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/mod_lua.c?rev=1519277&r1=1519276&r2=1519277&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/mod_lua.c (original)
+++ httpd/httpd/trunk/modules/lua/mod_lua.c Sun Sep  1 15:10:32 2013
@@ -1155,6 +1155,11 @@ static void lua_insert_filter_harness(re
     /* ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "LuaHookInsertFilter not yet implemented");
*/
 }
 
+static int lua_log_transaction_harness(request_rec *r)
+{
+    return lua_request_rec_hook_harness(r, "log_transaction", APR_HOOK_FIRST);
+}
+
 static int lua_quick_harness(request_rec *r, int lookup)
 {
     if (lookup) {
@@ -1219,6 +1224,15 @@ static const char *register_map_to_stora
     return register_named_file_function_hook("map_to_storage", cmd, _cfg,
                                              file, function, APR_HOOK_MIDDLE);
 }
+
+static const char *register_log_transaction_hook(cmd_parms *cmd, void *_cfg,
+                                                const char *file,
+                                                const char *function)
+{
+    return register_named_file_function_hook("log_transaction", cmd, _cfg,
+                                             file, function, APR_HOOK_FIRST);
+}
+
 static const char *register_map_to_storage_block(cmd_parms *cmd, void *_cfg,
                                                  const char *line)
 {
@@ -1226,6 +1240,7 @@ static const char *register_map_to_stora
                                               line);
 }
 
+
 static const char *register_check_user_id_hook(cmd_parms *cmd, void *_cfg,
                                                const char *file,
                                                const char *function,
@@ -1783,6 +1798,10 @@ command_rec lua_commands[] = {
     AP_INIT_TAKE2("LuaHookInsertFilter", register_insert_filter_hook, NULL,
                   OR_ALL,
                   "Provide a hook for the insert_filter phase of request processing"),
+    
+    AP_INIT_TAKE2("LuaHookLog", register_log_transaction_hook, NULL,
+                  OR_ALL,
+                  "Provide a hook for the logging phase of request processing"),
 
     AP_INIT_TAKE123("LuaScope", register_lua_scope, NULL, OR_ALL,
                     "One of once, request, conn, server -- default is once"),
@@ -1983,6 +2002,10 @@ static void lua_register_hooks(apr_pool_
     
     /* ivm mutex */
     apr_thread_mutex_create(&lua_ivm_mutex, APR_THREAD_MUTEX_DEFAULT, p);
+    
+    /* Logging catcher */
+    ap_hook_log_transaction(lua_log_transaction_harness,NULL,NULL,
+                            APR_HOOK_FIRST);
 }
 
 AP_DECLARE_MODULE(lua) = {



Mime
View raw message