'2019/05/21'에 해당되는 글 1건

  1. 2019.05.21 nginx json 로그


nginx에 json 로그가 없을 것이라 생각했는데.. 찾아보니 json을 제공한다. 
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format

그냥 지원하지 않을 것 같은 느낌인데.. 사실은 이미 지원하고 있다. 


Syntax:    log_format name [escape=default|json|none] string ...;
Default:    
log_format combined “...“;
Context:    http

 


log_format json_combined escape=json
 ‘{’
   ‘“time_local”:“$time_local”,’
   ‘“remote_addr”:“$remote_addr”,’
   ‘“remote_user”:“$remote_user”,’
   ‘“request”:“$request”,’
   ‘“status”: “$status”,’
   ‘“body_bytes_sent”:“$body_bytes_sent”,’
   ‘“request_time”:“$request_time”,’
   ‘“http_referrer”:“$http_referer”,’
   ‘“http_user_agent”:“$http_user_agent”’
 ‘}’;

 

 

access_log /var/log/nginx/access.log json_combined;

 


특히 기본 모듈에서 제공하는 기능이라 따로 모듈 추가를 하지 않아도 된다. 

 

 




Posted by '김용환'
,