Nginx uses a few different directives to control system logging. The one included in the core module is called error_log
.
error_log
directive
Syntax: error_log log_file log_level
.
log_file
: specifies the file where the logs will be written.log_level
: specifies the lowest level of logging to be recorded.
Logging levels
emerg
: emergency situations.alert
:crit
:error
:warn
:notice
:info
debug
:
Example:
|
|
error_log
is part of the core module; the access_log
is part of the HttpLogModule
. This provides the ability to customise the log.
log_format
directive
The log_format
directive is used to describe the format of a log entry using the plain text and variables.
General Syntax:
|
|
|
|
combined
comes predefined with Nginx.
access_log
directive
Syntax:
|
|
Specify compression of log file by adding gzip
:
|
|
Managing a log rotation
The command that actually rotates the logs is kill -USR1 /var/run/nginx.pid
. It sends signal to reload its log files.
Log rotation with logrotate
The logrotate
application is used to rotate logs.
|
|