public
Description: Log execution times and comments about a Rails block of code to its own log file.
Homepage: http://killswitchcollective.com/articles/49_organized_logs_with_logcabin
Clone URL: git://github.com/chrisjpowers/log_cabin.git
name age message
file README.rdoc Loading commit data...
file init.rb
directory lib/
README.rdoc

LogCabin

Developed by Chris Powers, Killswitch Collective (www.killswitchcollective.com)

Version 0.1, 11/18/2008

The LogCabin plugin is designed to give you the flexibility to write information about blocks of code and their execution times to specific log files in your Rails project.

This is especially useful when monitoring and debugging a specific set of code in a model or controller file. For example:

  class UsersController < ApplicationController
    def index
      LogCabin.log_to :users_query do |log|
        log.info "Finding all users with params = '#{params[:user_search].map{|k,v| "#{k}: #{v}"}.join(', ')}'"
        @users = User.search(params[:user_search])
        log.info "Found a total of #{@users.length} users"
      end
    end
  end

This would print this out to /log/users_query.log:

  INFO: Finding all users with params = 'last_name: Smith, city: Chicago'
  INFO: Found a total of 32 users
  TIME: Tue Nov 18 12:34:52 -0600 2008: Operation took 3.2876 seconds

It is also possible to pass an :if or :unless option to LogCabin#log_to, ex:

  LogCabin.log_to :users_query, :if => RAILS_ENV == 'development' do |log|
    log.info "This will not output anything unless we're in development"
    puts "But any other Ruby code ni this block will always be run"
  end