Plugins - Rows Logger

StarAdd to favorites

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

Usage

Just enjoy Rails as usual.

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'

ConnectionAdapters::AbstractAdapter#log

  --> log_info(sql, name, seconds)

ConnectionAdapters::AbstractAdapter#log

  --> log_info(sql, name, seconds, result = nil)
        --> log_result_info(result)
              --> ConcreteAdapter#count_result(result)

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.

Maiha

http://habtm.com/articles/2006/11/08/rows-logger

http://wota.jp/svn/rails/plugins/branches/stable/rows_logger/

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Statistics and Logs

Tags

Comments

Add a comment

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.
Recruiting software

Have a comment?