Lua生成log文件

寫了一個簡單的lua腳本按照日期天天生成一個log文件,記錄請求的body和相關參數lua

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()
相關文章
相關標籤/搜索