Opened 2 years ago

Last modified 13 months ago

#2332 new enhancement

Include $request_id in error.log messages

Reported by: heikojansen@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.19.x
Keywords: Cc:
uname -a: Linux d7-p1 5.3.18-150300.59.43-default #1 SMP Sun Jan 23 19:27:23 UTC 2022 (c76af22) x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.21.5
built by gcc 7.5.0 (SUSE Linux)
built with OpenSSL 1.1.1d 10 Sep 2019
TLS SNI support enabled
configure arguments: --prefix=/usr/ --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/run/nginx.pid --lock-path=/run/nginx.lock --http-client-body-temp-path=/var/lib/nginx/tmp/ --http-proxy-temp-path=/var/lib/nginx/proxy/ --http-fastcgi-temp-path=/var/lib/nginx/fastcgi/ --http-uwsgi-temp-path=/var/lib/nginx/uwsgi/ --http-scgi-temp-path=/var/lib/nginx/scgi/ --user=nginx --group=nginx --without-select_module --without-poll_module --with-threads --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-perl=/usr/bin/perl --with-mail=dynamic --with-mail_ssl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_ssl_preread_module --with-pcre --with-pcre-jit --with-cc-opt='-fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -fPIC -D_GNU_SOURCE' --with-ld-opt='-Wl,-z,relro,-z,now -pie' --with-compat

Description

In order to make debugging easier it might make sense to include the $request_id variable in error.log messages when these are associated with incoming requests.

Change History (1)

comment:1 by anthumchris@…, 13 months ago

This can currently be achieved by adding an access_log entry to the error_log file

nginx.conf

# Add spaces to mirror horizontal placement of error log's connection serial number
log_format requestid '$time_iso8601 [error]          *$connection $request_id';

server {
  ...
  error_page 404 @404;

  location @404 {
    add_header x-request-id $request_id always;
    access_log logs/fail.error.log requestid;
    error_log  logs/fail.error.log;
  }

  location /fail {
    return 404;
  }
}

fail.error.log

2023/03/08 09:30:43 [error] 45212#4292110: *60 open() "/usr/local/nginx/html/fail" failed (2: No such file or directory), client: 127.0.0.1, server: , request: "GET /fail HTTP/2.0", host: "localhost"
2023-03-08T09:30:43-07:00 [error]          *60 7d8ea5ebd7f3d39d844a24f5ab1fa535
Version 0, edited 13 months ago by anthumchris@… (next)
Note: See TracTickets for help on using tickets.