Logging to Papertrail usually requires a running syslog-compatible server. pt-log provides a simpler interface to write a single message: one local file. Just start the container then append lines to the local file. Every line will be sent to Papertrail.
Alternatively, if a LISTEN_PORT
is specified, messages will be received via TCP over that port. Use either a mounted file or a LISTEN_PORT
, but not both.
The (tiny) image is based on Alpine Linux.
Warning: this is intended for low-throughput dev usage. Multiple simultaneous writes to the logfile could result in lost log lines.
This starts the pt-log container and uses variables in the current shell to name the "system" (host) and "program" (logfile) in Papertrail. Docker will keep it running.
Configuration is performed at runtime using environment variables.
Required environment variables:
EXT_USER
- user to log asEXT_HOST
- host to log asPT_DEST
- Papertrail log destination hostPT_PORT
- Papertrail log destination port
Optional environment variables:
LISTEN_PORT
- listen for log messages on this TCP port. Do not specify this and also mount the logfile.
touch ~/.pt-log
docker run \
--detach=true \
--name pt-log \
--env="EXT_USER=$(id -ng $USER)" \
--env="EXT_HOST=$HOSTNAME" \
--env="PT_DEST=logs.papertrailapp.com" \
--env="PT_PORT=514" \
--restart=always \
--volume="$HOME/.pt-log:/pt-log/$(id -ng $USER)" \
gcr.io/surveyadmin-001/pt-log
docker run \
--detach=true \
--name pt-log \
--env="EXT_USER=$(id -ng $USER)" \
--env="EXT_HOST=$HOSTNAME" \
--env="PT_DEST=logs.papertrailapp.com" \
--env="PT_PORT=514" \
--env="LISTEN_PORT=12004" \
-p 12004:12004 \
--restart=always \
gcr.io/surveyadmin-001/pt-log
echo "$(date) hey there - test" >> ~/.pt-log
Or, if you used LISTEN_PORT
, above:
echo "$(date) hey there - test" | nc host 12004
touch ~/.pt-log
docker run \
--rm \
-it \
--name pt-log \
--env="EXT_USER=$(id -ng $USER)" \
--env="EXT_HOST=$HOSTNAME" \
--env="PT_DEST=logs.papertrailapp.com" \
--env="PT_PORT=514" \
--volume="$HOME/.pt-log:/pt-log/$(id -ng $USER)" \
gcr.io/surveyadmin-001/pt-log \
/bin/sh
The logger
command (provided by the bsdutils
package on Ubuntu) can also write directly to Papertrail's endpoints, but will not encrypt. pt-log encrypts messages before they are sent over the wire.
Copyright (C)2020 C-SATS, Inc.
License: AGPL v3. See COPYING for details.