If you haven't already done so, you have to install the logworm gem first:
$ sudo gem install logworm_amqp
When you create a new project, we'll give you a 'logworm URL' for it. Let's say, for example, that it is:
logworm://Ub5sOstT9w:GZi0HciTVcoFHEoIZ7@db.logworm.com/OzO71hEvWYDmncbf3C/J7wq4X06MihhZgqDeB/
You have to copy that URL into a file named .logworm in your application's top-level directory:
$ cd <yourapp>
$ cat > .logworm
logworm://Ub5sOstT9w:GZi0HciTVcoFHEoIZ7@db.logworm.com/OzO71hEvWYDmncbf3C/J7wq4X06MihhZgqDeB/
We'll use that URL in the rest of the document, but don't forget it's an example! You'll get a different one for your real project.
Then add the file to your .gitignore. This will ensure that your URL is not copied into your Git repository, be it Heroku's, GitHub's, or any other Git repository that you're using. You want to keep this URL private, as it has the security keys that ensure that you and only you can access it:
$ echo '.logworm' >> .gitignore
If you're running Rails 2.3.4 or 2.3.8
Edit environment.rb and add
config.gem 'logworm_amqp'
inside the Rails::Initializer.run block.
If you're running Rails 3.0.0
Add gem 'logworm_amqp' to Gemfile
Edit config/application.rb and add
config.middleware.use(Logworm::Rack)
inside the class Application < Rails::Application block.
If you're running a Rack-based framework
Edit your config.ru file and indicate that you want to use logworm's Rack middleware. For example, for a Sinatra application you'd have:
$ cat config.ru
require "myapp"
require "logworm_amqp"
use Logworm::Rack
run Sinatra::Application
This basic setup will automatically log basic information about each HTTP request that your application receives. To test this, start your application locally in production mode (logworm doesn't record any data in development mode, to keep your logs clean, unless you specify that in the configuration) and visit a couple of pages; the client will start sending logging information to our servers. There is a command-line application that lets you tail those logs:
$ ./script/server -e production
[...]
$ lw-tail web_log
2010-03-02 @ 15:39:38 GMT ==>
_request_id: "23949566400260-1267544378088"
_ts_utc: 1267544378089
input: "table=sales&keys%5B%5D=customer&values%5B%5D=keith&keys%5B%5D=total&values%5B%5D=100&keys%5B%5D=&values%5B%5D="
profiling: 0.000613
queue_size: "-1"
request_ip: "24.63.134.228"
request_method: "POST"
request_path: "/post"
response_status: 200
summary: "POST /post - 200 0.000613"
2010-03-02 @ 15:39:40 GMT ==>
_request_id: "23949566400260-1267544380865"
_ts_utc: 1267544380866
input: ""
profiling: 0.00056
queue_size: "-1"
request_ip: "24.63.134.228, 10.242.45.203"
request_method: "GET"
request_path: "/favicon.ico"
response_status: 404
summary: "GET /favicon.ico - 404 0.00056"
Make sure you're running your app in production!.
When you're ready to push to Heroku, don't forget to add the 'logworm_amqp' gem to your .gems file:
$ echo 'logworm_amqp' >> .gems
$ git add .
$ git commit -m "Added logworm logging!"
$ git push heroku master
You'll also need to run a command to push the logworm URL into the Heroku application:
$ heroku config:add LOGWORM_URL="logworm://Ub5sOstT9w:GZi0HciTVcoFHEoIZ7@db.logworm.com/OzO71hEvWYDmncbf3C/J7wq4X06MihhZgqDeB/"
Adding config vars:
LOGWORM_URL => logworm://Ub5sOstT9w:GZi0HciTVcoFHEoIZ7@db.logworm.com/OzO71hEvWYDmncbf3C/J7wq4X06MihhZgqDeB/
Restarting app...done.
You only need to do this just once.