Skip to content

Instantly share code, notes, and snippets.

@paulmelnikow
Last active August 29, 2015 14:11
Show Gist options
  • Save paulmelnikow/19ad6fc5a10dee6e9d08 to your computer and use it in GitHub Desktop.
Save paulmelnikow/19ad6fc5a10dee6e9d08 to your computer and use it in GitHub Desktop.
Rake task to set up secure logging from from Heroku to Papertrail
namespace :heroku do
task :create_logger, [:name, :dst] do |t, args|
# To use this:
#
# 1. Add a new system. Choose "Alternative". Or go to
# https://papertrailapp.com/systems/new
# 2. Choose "I use Heroku"
# 3. Type the name of the app and click Save. You'll see a path like
# host.papertrailapp.com:12345. Make a note of it.
# 4. Go back into Log Destinations and click Edit Settings.
# Under TCP, clear the box for Plain text and check the box for
# TLS encryption.
# 5. Run heroku:create_logger[your_app,host.papertrailapp.com:12345]
# 6. The script will create a folder for the logging app. Move it out of the way if necessary.
# 7. Add a log drain using the command it provides.
#
require 'securerandom'
die "name is required" unless args.name
die "dst is required" unless args.dst
# FIXME dst should be host.papertrailapp.com:12345
name = args.name
app_name = "#{args.name}-logger"
dst = args.dst
token = SecureRandom.hex(20)
raise unless system "heroku create #{app_name} --buildpack https://github.com/kr/heroku-buildpack-go.git"
raise unless system "heroku config:set -r #{app_name} PORT=443 DEPLOY=#{name} PEMFILE=vendor/papertrail-bundle.pem ENFORCE_SSL=1 FORWARD_DEST=#{dst} TOKEN_MAP=syslog:#{token} --app #{app_name}"
raise unless system "git clone https://github.com/heroku/log-iss.git #{app_name}"
Dir.chdir app_name do
raise unless system "heroku git:remote -a #{app_name}"
raise unless system "git push heroku master"
end
puts
puts 'Add it to your app:'
puts
puts "heroku drains:add https://syslog:#{token}@#{app_name}.herokuapp.com/logs --app YOUR_APP"
puts
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment