Skip to content

Instantly share code, notes, and snippets.

@atrepca
Last active December 4, 2023 21:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrepca/7159195 to your computer and use it in GitHub Desktop.
Save atrepca/7159195 to your computer and use it in GitHub Desktop.
Send Heroku logs to an rsyslog server and save them to separate files by application
  • Add a Heroku drain for your app to forward the logs to your rsyslog server:

      heroku drains:add --app my-prod-app syslog://logging01.prod.mydomain.net:514
    
  • List the drain you just created to get the unique Drain ID:

      heroku drains -x --app my-prod-app
    
  • On the rsyslog server save the logs coming from Heroku to separate files, without duplicating to /var/log/messages (thanks to the & ~). Create a /etc/rsyslog.d/90-heroku.conf file containing:

      if $HOSTNAME startswith 'Drain_ID' then /opt/log/heroku/my-prod-app.log
      & ~
    
  • Duplicate the above block for each log file, with & ~ on a separate line each time. Restart rsyslog when you're done and don't forget to set up logrotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment