码迷,mamicode.com
首页 > 其他好文 > 详细

Lua生成log文件

时间:2016-05-10 15:17:49      阅读:221      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!