Rows Logger plugin

Plugin details

This plugin offers rich information about result sets to AR logs.

Websitehttp://habtm.com/articles/2006/11/08/rows-logger Repositoryhttp://wota.jp/svn/rails/plugins/branches/stable/rows_logger/ Author Maiha Tags log LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://wota.jp/svn/rails/plugins/branches/stable/rows_logger/

===Example

Consider some read operations like this.

  Member.count
  Member.find(:all)



That usually makes following log.

  SQL (0.000300)   SELECT count(*) AS count_all FROM members
  Member Load (0.000482)   SELECT * FROM members



RowsLogger appends information about rows count to the log.

  SQL (0.000301) (1 Row)   SELECT count(*) AS count_all FROM members
  Member Load (0.000415) (3 Rows)   SELECT * FROM members




===For Developpers

This plugin modfies following methods.

  'ConnectionAdapters::AbstractAdapter#log'
  'ConnectionAdapters::AbstractAdapter#log_info'



before
ConnectionAdapters::AbstractAdapter#log
--> log_info(sql, name, seconds)

after
ConnectionAdapters::AbstractAdapter#log
--> log_info(sql, name, seconds, result = nil)
--> log_result_info(result)
--> ConcreteAdapter#count_result(result)


an example for concrete adapter

ConnectionAdapters::MysqlAdapter#count_result
  protected
  def count_result(result)
    result.num_rows
end




===Count Result Method

The 'count_result' method of Adapter class should return count of result set from 'result' object, where 'result' is an object generated by 'log' method. This is used as result information.

For exmaple, although this is nonsencial definition,

def count_result(result)
    0
end



this code always appends "(0 Rows)" to the log. The returned value is directly used even if it is not a numeric value. But no information will be appended in following cases.

1) when 'count_result' method returns nil
2) when 'count_result' method is not defined in current adapter


===Note

'count_result' method should be defined as 'protected' or 'public' because we check whether it is implemented or not in current adapter by using 'respond_to?' method.

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: scott, 7 months ago