Consul
Consul Template logs
This page describes the logging process for Consul Template.
Set log level
To set the log level for Consul Template, use the -log-level
flag:
$ consul-template -log-level info ...
You can also use the CONSUL_TEMPLATE_LOG_LEVEL
environment variable to set the log level.
$ export CONSUL_TEMPLATE_LOG_LEVEL=info && consul-template ...
The command outputs the log in the standard output.
# ...
[INFO] (cli) received redis from Watcher
[INFO] (cli) invoking Runner
# ...
When debugging, you can also specify the level as debug:
$ consul-template -log-level debug ...
The command outputs the log in the standard output.
# ...
[DEBUG] (cli) creating Runner
[DEBUG] (cli) creating Consul API client
[DEBUG] (cli) creating Watcher
[DEBUG] (cli) looping for data
[DEBUG] (watcher) starting watch
[DEBUG] (watcher) all pollers have started, waiting for finish
[DEBUG] (redis) starting poll
[DEBUG] (service redis) querying Consul with &{...}
[DEBUG] (service redis) Consul returned 2 services
[DEBUG] (redis) writing data to channel
[DEBUG] (redis) starting poll
[INFO] (cli) received redis from Watcher
[INFO] (cli) invoking Runner
[DEBUG] (service redis) querying Consul with &{...}
# ...
Log to file
Consul Template can log to file as well. Logging to file is particularly useful in use cases where it is not trivial to capture stdout and/or stderr. For example, we recommend logging to file when Consul Template is deployed as a long running service.
These are the relevant CLI flags:
-log-file
- writes all the Consul Template log messages to a file. This value is used as a prefix for the log file name. The current timestamp is appended to the file name. If the value ends in a path separator,consul-template-
will be appended to the value. If the file name is missing an extension,.log
is appended. For example, settinglog-file
to/var/log/
would result in a log file path of/var/log/consul-template-{timestamp}.log
.log-file
can be combined with-log-rotate-bytes
and-log-rotate-duration
for a fine-grained log rotation experience.-log-rotate-bytes
- to specify the number of bytes that should be written to a log before it needs to be rotated. Unless specified, there is no limit to the number of bytes that can be written to a log file.-log-rotate-duration
- to specify the maximum duration a log should be written to before it needs to be rotated. Must be a duration value such as30s
. Defaults to24h
.-log-rotate-max-files
- to specify the maximum number of older log file archives to keep. Defaults to 0 (no files are ever deleted). Set to-1
to discard old log files when a new one is created.