apache 下 lua完善网站记录日志
目的
网站日志一直是运维的重要工具,比如一个会员的轨迹追踪,请求和响应内容等,apache,nginx等的默认配置明显不够使用,code写日志那就是灾难,很久以前用lua在nginx上实现一个,今天记录apache下lua实现。老年码农,不分享
nginx简单记录
access_by_lua_file
body_filter_by_lua_file
log_by_lua_file
apache
原理同nginx
开启mod_lua
设置省略…
lua源码:
require "apache2"
require "string"
function input_filter(r)
local time=os.time()
local input = '时间:'..os.date('%Y-%m-%d %H:%M:%S',time)..' 路径:'..r.uri..' 参数:'
local reg = ''
local isformdata=nil
coroutine.yield()
while bucket do
reg = reg..bucket
coroutine.yield(bucket)
end
for k,v in string.gmatch(reg,'%s name="([%a_%-%w] )"%s ([%a_%-%w] )%s ') do
input=input..k.."="..v.."&";
isformdata=1
end
if isformdata ==nil then
input=input..reg
end
input=input..r.args
logger(input)
return apache2.OK
end
function output_filter(r)
local input =' 结果'
coroutine.yield()
while bucket do
input = input..bucket
coroutine.yield(bucket)
end
local time=os.time()
logger(input..'[时间:'..os.date('%Y-%m-%d %H:%M:%S',time).."]\n")
end
function logger(msg)
local file = io.open('D:/worker/public/secret.log', 'a')
if file then
file:write(string.format("%s",msg))
file:close()
return true
end
return false
end
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhiefika
系列文章
更多
同类精品
更多
-
解决Mybatis报错org.apache.ibatis.reflection.ReflectionException: There is no getter for property named
-
CVE-2021-27905 Apache Solr SSRF漏洞
-
Linux环境Ubuntu系列安装和部署Apache2
-
IDEA创建Maven项目报错- Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model
-
tomcat打不开 跳出弹窗显示指定服务未安装解决方法详细流程
-
Apache HttpComponents 使用
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
excel图片置于文字下方的方法
PHP中文网 06-27 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
微信提示登录环境异常是什么意思原因
PHP中文网 04-09 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22 -
微信人名旁边有个图标有什么用
PHP中文网 03-11