Skip to content

log — the log ​

yaml
log:
  level: info
  output: /var/log/ours.log
  timestamp: true
FieldMeaningDefault
leveltrace, debug, info, warn, errorinfo
outputstderr, stdout or a path to a file (appended to)stderr
formattext or json (one object per line)text
timestampPrint the time (UTC) on every linetrue; on stderr under systemd (JOURNAL_STREAM), false: the journal adds the time
disabledTurn the log offfalse
  • warning is the same as warn; fatal and panic are the same as error.
  • Text logs use color on terminals. JSON logs use plain text on every output.
  • The section also applies on reload. The level, format and output can be changed without restarting.
  • An unknown level or format is an error of check, startup or reload.

With format: json, each event has level, fields and, when enabled, timestamp. Connection details such as addresses and the connection ID can still be part of fields.message:

json
{"level":"INFO","fields":{"message":"[12] rejected by rule[3]"}}

For a service managed by systemd, leave output at stderr and use journald for retention. For a file, configure external rotation. After renaming it, send SIGUSR1 to reopen the active log path, for example with systemctl kill --kill-who=main --signal=SIGUSR1 ours in a logrotate postrotate script. If reopening fails, ours keeps writing to the previous file.

FATAL … messages about a failed start are printed to stderr regardless of the section.

What goes to the log:

  • The first line is the build: ours 0.1.0 (<commit>, <date>, <target>) starting; on a stop by signal, ours stopping (SIGTERM) and ours stopped. A log without these lines ended some other way.
  • The lines of one connection start with its number: [12] inbound/trojan[in]: [alice] inbound connection from … to … (the user name is on the same line), [12] outbound/…, [12] rejected by rule[3] — rejected by the rule with this number in route.rules.
  • A connection the inbound closed before routing (a failed TLS handshake, a wrong password, a scanner, a visitor of the REALITY cover site) is written at debug; at info, the first one per minute per inbound, with the number of the others: … process connection from …: … (41 more refused since the last such line; debug logs each). The counter is ours_inbound_refused_total (metrics).
  • A panic (a bug in ours) is written as ERROR panic in thread … at <file>:<line>: … with the version and commit, to the configured output, and if that is not stderr, to stderr as well. A panic in a connection closes only that connection; any other panic stops the process the same way as SIGTERM (the auto_nft interception is removed), with exit code 1 and a backtrace in the log. A backtrace of a connection panic needs RUST_BACKTRACE=1.

With the dashboard on (--dashboard or admin.listen) the last 256 log records (not below the configured level) are visible in the Events section of the Dashboard.

GPL-3.0-or-later