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 directly
development:
  apikey: "YOUR_API_KEY"
  database: myapp
  debug_mode: true  # enable debug mode

# logging via td-agent (fluent)
production:
  agent: "localhost:24224"
  tag: td.myapp

# disable logging
test:

Logging events

You can log anytime using ‘TD.event.post’ method:

class MyClass
  def mymethod
    TD.event.post('table_name', {:foo=>:bar})
  end
end

Rails extension

In rails application, you can use ‘TD.event.attribute’ to set static attribute to all events:

class ApplicationController
  def authenticate
    # set 'uid' attribute to succeeding event logs
    TD.event.attribute[:uid] = 198
  end
end

class MyController < ApplicationController
  def mymethod
    authenticate()
    # this event includes 'uid' attribute
    TD.event.post('table_name', {:foo=>:bar})
  end
end
Copyright

Copyright © 2011 Treasure Data Inc.

License

Apache License, Version 2.0