Logging
Logging
To provide context to each log message, structured logging
is used. Thus
instead of free text log messages without any specific format, the log data is
to some extent divided into fields of name-value pairs, making the logs more
coherent and more suitable for processing by external tools.
Log messages related to a specific HTTP request include the log field named
request_id
which can be used to filter out specific requests.
The log field named topic
is always present and is used to separate different
areas of logging. The current topics are access
, messages
and error
, and
are used to log HTTP access, debug messages and panic stack traces,
respectively.
As a comparison, the topics are similar to having separate files for access logging, debug messages and errors in a conventional file-based logging system.
Log formats
When run from the command line ew-hlsingest can log in one of the formats
consolepretty,
consolejsonor
journalddepending on the value of the
-logformatparameter. Logging can be disabled by using the value
discard`.
$ ew-hlsingest -upstream http://127.0.0.1 -logformat consolejson
consolepretty
logs to standard output (stdout
) in a human-readable format.
Each log line starts with the date and the log message followed by the context-
dependent log fields:
2022-02-07T11:54:42Z INF Incoming request bytes_out=27592 latency_ms=6.18251 method=GET ...
consolejson
logs to stdout
using a JSON object for each message:
{"level":"info","topic":"access","time":"2022-02-07T12:06:07Z","bytes_out":27592, ...}
When run as a systemd
service, ew-hlsingest logs directly to
journaldusing the
logjournaldconfiguration parameter. When stored in
journald`, field
names are upper case whereas the values keep their format. Some examples:
To see entries a specific channel:
$ journalctl -u ew-hlsingest CHANNEL=ch1 -o verbose
To continuously monitor the service:
$ journalctl -fu ew-hlsingest
Log levels
At startup the log level is set to info
.
The log level can be changed by posting a form-field named level
to the
loglevel
endpoint on the `ew-hlsingest server:
$ curl -F level=debug ew-hlsingest-server:8090/loglevel
The available log levels and how they relate to systemd priority values is listed below:
Log level Systemd priority
trace 7
debug 7
info 6
warn 4
error 3
fatal 2
panic 0
To e.g. see all error and warning messages using journalctl:
$ journalctl -u ew-hlsingest PRIORITY=3 PRIORITY=4
Messages with higher level than the configured one will not be logged.