• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

apache 下 lua完善网站记录日志

武飞扬头像
weixin_43294972
帮助2

目的

网站日志一直是运维的重要工具,比如一个会员的轨迹追踪,请求和响应内容等,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
系列文章
更多 icon
同类精品
更多 icon
继续加载