Sign inSign up

meonkeys/pt-log

By meonkeys

•Updated about 10 years ago

local, secure log-to-Papertrail microservice

Image
0

4.4K

meonkeys/pt-log repository overview

⁠pt-log - local, secure log-to-Papertrail microservice

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.

⁠Start the logger container

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:

  1. EXT_USER - user to log as
  2. EXT_HOST - host to log as
  3. PT_DEST - Papertrail log destination host
  4. PT_PORT - Papertrail log destination port

Optional environment variables:

  1. LISTEN_PORT - listen for log messages on this TCP port. Do not specify this and also mount the logfile.
⁠mounted 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)" \
  meonkeys/pt-log
⁠TCP port
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 \
  meonkeys/pt-log

⁠Log a message to Papertrail

echo "$(date) hey there - test" >> ~/.pt-log

Or, if you used LISTEN_PORT, above:

echo "$(date) hey there - test" | nc host 12004

⁠How to debug the container

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)" \
  meonkeys/pt-log \
  /bin/sh

⁠Why not just use logger?

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)2016 Adam Monsen.

License: AGPL v3. See COPYING for details.

Tag summary

Content type

Image

Digest

Size

6.4 MB

Last updated

about 10 years ago

docker pull meonkeys/pt-log