Treasure Data logging library for Rails

Getting Started

Add the following line to your Gemfile:

gem 'td-logger'

For Rails 2.x (not tested) without Bundler, edit environment.rb and add to the initalizer block:

config.gem "td-logger"

And then add config/treasure_data.yml file as following:

# logging to Treasure Data directry
development:
  apikey: "YOUR_API_KEY"
  database: myapp
  auto_create_table: true

# logging via td-agent
production:
  agent: "localhost:24224"
  tag: myapp

# disable logging
test:

Logging actions

Add ‘add_td_tracer’ line to your controller classes:

class YourController < ApplicationController
  def myaction
    # ...
  end
  add_td_tracer :myaction, 'mytable'
end

It logs “controller”:“your”,“action”:“myaction”. Additionally, routing parameters are included automatically.

You can add environment variables by adding ‘extra’ option as follows:

# logs client address on the 'addr' column
add_td_tracer :myaction, 'mytable', :extra=>{:REMOTE_ADDR=>:addr}

# logs referer and path info
add_td_tracer :myaction, 'mytable', :extra=>{:HTTP_REFERER=>:referer, :PATH_INFO=>:path}

Add ‘static’ option to add constant key-value pairs:

add_td_tracer :myaction, 'mytable', :static=>{:version=>1}
Copyright

Copyright © 2011 Treasure Data Inc.

License

Apache License, Version 2.0