Lua生成log文件


寫了一個簡單的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()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM