Logging

Configuring Logging

The NATS server provides various logging options that you can set via the command line or the configuration file.

Command Line Options

The following logging operations are supported:
1
-l, --log FILE File to redirect log output.
2
-T, --logtime Timestamp log entries (default is true).
3
-s, --syslog Enable syslog as log method.
4
-r, --remote_syslog Syslog server address.
5
-D, --debug Enable debugging output.
6
-V, --trace Trace the raw protocol.
7
-VV Verbose trace (traces system account as well)
8
-DV Debug and Trace.
9
-DVV Debug and verbose trace (traces system account as well)
Copied!

Debug and trace

The -DV flag enables trace and debug for the server.
1
nats-server -DV -m 8222 -user foo -pass bar
Copied!

Log file redirect

1
nats-server -DV -m 8222 -l nats.log
Copied!

Timestamp

If -T false then log entries are not timestamped. Default is true.

Syslog

You can configure syslog with UDP:
1
nats-server -r udp://localhost:514
Copied!
or syslog:
1
nats-server -r syslog://<hostname>:<port>
Copied!
For example:
1
syslog://logs.papertrailapp.com:26900
Copied!

Using the Configuration File

All of these settings are available in the configuration file as well.
1
debug: false
2
trace: true
3
logtime: false
4
logfile_size_limit: 1GB
5
log_file: "/tmp/nats-server.log"
Copied!

Log Rotation

Introduced in NATS Server v2.1.4, NATS allows for auto-rotation of log files when the size is greater than the configured limit set in logfile_size_limit. The backup files will have the same name as the original log file with the suffix .yyyy.mm.dd.hh.mm.ss.micros.
You can also use NATS-included mechanisms with logrotate, a simple standard Linux utility to rotate logs available on most distributions like Debian, Ubuntu, RedHat (CentOS), etc., to make log rotation simple.
For example, you could configure logrotate with:
1
/path/to/nats-server.log {
2
daily
3
rotate 30
4
compress
5
missingok
6
notifempty
7
postrotate
8
kill -SIGUSR1 `cat /var/run/nats-server.pid`
9
endscript
10
}
Copied!
The first line specifies the location that the subsequent lines will apply to.
The rest of the file specifies that the logs will rotate daily ("daily" option) and that 30 older copies will be preserved ("rotate" option). Other options are described in logrorate documentation.
The "postrotate" section tells NATS server to reload the log files once the rotation is complete. The command `kill -SIGUSR1cat /var/run/nats-server.pid``` does not kill the NATS server process, but instead sends it a signal causing it to reload its log files. This will cause new requests to be logged to the refreshed log file.
The /var/run/nats-server.pid file is where NATS server stores the master process's pid.

Some Logging Notes

  • The NATS server, in verbose mode, will log the receipt of UNSUB messages, but this does not indicate the subscription is gone, only that the message was received. The DELSUB message in the log can be used to determine when the actual subscription removal has taken place.
Last modified 10d ago