首页 > 其他 > 详细

Lua生成log文件

时间:2016-05-10 15:17:02      阅读:465      评论:0      收藏:0      [点我收藏+]

写了一个简单的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()

 

Lua生成log文件

原文:http://www.cnblogs.com/alphago-1/p/5477907.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!