Setting up remote logging to papertrail using chef
01 Jan 2014One 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 \"*.* @logs.papertrailapp.com:PORT\" >> /etc/rsyslog.conf" do
not_if "grep -q papertrail /etc/rsyslog.conf"
end
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"
else
echo "installing papertrail"
echo "*.* @logs.papertrailapp.com:12170" | sudo tee -a /etc/rsyslog.conf
fi
to quickly test the logging by writing to the log:
logger testing connection