Setting up remote logging to papertrail using chef

One of the options to send logs to papertrail on a unix system is to use the syslog. When using chef for provisioning, the following ruby code will modify the syslog configuration file but only if it was not already modified before:

PORT = 12345 # make sure to replace with your account's port
execute "echo \"*.*\" >> /etc/rsyslog.conf" do
  not_if "grep -q papertrail /etc/rsyslog.conf"
execute "/etc/init.d/rsyslog restart"

or if you're using bash scripts for provisioning:

if grep -q papertrail /etc/rsyslog.conf; then
  echo "papertrail already installed"
  echo "installing papertrail"
  echo "*.*" | sudo tee -a /etc/rsyslog.conf

to quickly test the logging by writing to the log:

logger testing connection

Follow me for updates on similar new posts I write or tweet about this post.