写了一个简单的lua脚本按照日期每天生成一个log文件,记录请求的body和相关参数
1 local method = ngx.var.request_method 2 local reqbody = ngx.decode_args(ngx.ctx.reqbody) 3 local msg = string.format("lualog is here... time:%s,方法类型:%s,req_body:%s,response_code:%s,response_body:%s",os.date("%X",os.time()),method,reqbody.biData,"",ngx.var.resp_body); 4 local file_name="local_access_"..os.date("%Y-%m-%d", os.time())..".log" 5 local f = assert(io.open(file_name,"a"),"读取文件失败") 6 7 msg=msg..f:seek("end") 8 f:write("\n"..msg) 9 f:flush()
时间: 2024-10-28 23:08:33