Home > Operation and Maintenance > Nginx > How to record logs in JSON format in nginx

How to record logs in JSON format in nginx

王林
Release: 2023-05-12 11:43:06
forward
1523 people have browsed it

Define nginx log format:

Copy code The code is as follows:

log_format logstash_json '{ "@timestamp": "$time_local", '
                                                             ": { '
           '"remote_addr": "$remote_addr", '
             '"remote_user": "$remote_user", '
           '"body_bytes_sent": "$body_bytes_sent", '
            ' "request_time": "$request_time", '
             '"status": "$status", '
                                       "request_method": "$request_method" , '
          '"http_referrer": "$http_referer", '
             '"body_bytes_sent": "$body_bytes_sent", '
               '"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_user_agent ": "$http_user_agent" } }';

Specify the log format:


Copy the code The code is as follows:

access_log /data/logs/ nginx/www.jb51.net.access.log logstash_json;


The log output is as follows:

How to record logs in JSON format in nginx

is not conducive to reading. Copy to beautify format.

How to record logs in JSON format in nginx

The above is the detailed content of How to record logs in JSON format in nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Backslash present in Json
From 1970-01-01 08:00:00
0
0
0
Get: Transfer JSON data
From 1970-01-01 08:00:00
0
0
0
mysql storage json error
From 1970-01-01 08:00:00
0
0
0
javascript - Problems with displaying json data
From 1970-01-01 08:00:00
0
0
0
Find matching integers in JSON.
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template