1. 安装
 
  1. opm get p0pr0ck5/lua-resty-logger-socket
 
2. 使用
   location   lua_by_lua_block 
 
  1. log_by_lua_block {
  2. local logger = require "resty.logger.socket"
  3. ngx.log(ngx.ERR, "Test Syslog: ", "call")
  4. if not logger.initted() then
  5. local ok, err = logger.init {
  6. host="syslog-ng-host",
  7. port=514,
  8. sock_type="udp",
  9. flush_limit = 1,
  10. --drop_limit = 5678
  11. }
  12. if not ok then
  13. ngx.log(ngx.ERR, "failed to initialize the logger: ", err)
  14. return
  15. end
  16. end
  17. -- construct the custom access log message in
  18. -- the Lua variable "msg"
  19. local url = ngx.var.uri
  20. local method = ngx.req.get_method()
  21. local headers = ngx.req.raw_header(true)
  22. -- tbl
  23. local params_var = ngx.req.get_uri_args()
  24. local client_ip = ngx.var.remote_addr
  25. -- tbl
  26. local user_agent = ngx.req.get_headers()["User-Agent"]
  27. local referer = ngx.req.get_headers()["Referer"] or ""
  28. local cookies = ngx.req.get_headers()["Cookie"]
  29. local bytes, err = logger.log("test")
  30. local bytes, err = logger.log(client_ip.." "..table.concat(params_var).." "..user_agent.." "..referer.." "..cookies.." "..url.." "..method)
  31. if err then
  32. ngx.log(ngx.ERR, "failed to log message: ", err)
  33. return
  34. end
  35. }
  
3. log server 
 
     syslog-ng  其中启用  udp  server  同时可以安装对应的后端storage
  1. yum install -y syslog-ng
 
4.  log 查询
     
      syslog-ng  server   
  1. tail - f /var/log/message
 
5. 参考资料
 
 
    
 
 

最新文章

  1. 使用LogMaster4Net实现应用程序日志的集中管理
  2. ajax内调用WCF服务
  3. [NHibernate]Nullables
  4. Codeforces Round #277.5 (Div. 2) ABCDF
  5. UIProgressView(进度条控件)
  6. c# 基本值类型及其默认值
  7. auto_ptr, which can release the space automatically
  8. JAVA集合差异
  9. Secure CRT 如何连接虚拟机里面的CentOS系统——当主机使用无线网的时候 作者原创 欢迎转载
  10. Unicode 与 Unicode Transformation Format(UTF,UTF-8 / UTF-16 / UTF-32)
  11. P1879 [USACO06NOV]玉米田Corn Fields
  12. HTTP的一些基本概念
  13. 关于 /bin/bash: warning: setlocale: LC_ALL: cannot change locale (en.US_UTF-8) 问题
  14. Android 6.0系统动态请求系统相机权限
  15. 变量计算——强制类型转换的js面试题
  16. Luogu2612 ZJOI2012 波浪 DP
  17. freeRTOS中文实用教程3--中断管理之计数信号量
  18. Nand Flash 驱动框架
  19. loj SDOI2017数字表格
  20. linux输入密码的实现

热门文章

  1. HighCharts常用设置
  2. 备注Quartz触发器设置
  3. 20.并发容器之ArrayBlockingQueue和LinkedBlockingQueue实现原理详解
  4. mysql too many connections解决方法
  5. write 系统调用耗时长的原因
  6. tcpdump 使用实例
  7. C#运算符笔记
  8. linux中的/usr,/var,/opt目录详解
  9. Prism 4 文档 ---第8章 导航
  10. HTML条件注释判断浏览器版本命令