each-with-logging

each_with_logging will warn caller, index and length.

require 'each-with-logging'

[1,2,3,4].each_with_logging {|i|
  p i
}

# m.rb:3:in `<main>' 1 / 4
# 1
# m.rb:3:in `<main>' 2 / 4
# 2
# m.rb:3:in `<main>' 3 / 4
# 3
# m.rb:3:in `<main>' 4 / 4
# 4

You can use each_with_logging with Logger.

require 'each-with-logging'
require 'logger'
logger = Logger.new(STDOUT)

[1,2,3,4].each_with_logging(logger) {|i|
  p i
}

# D, [2011-03-07T10:55:48.014898 #92103] DEBUG -- : l.rb:5:in `<main>' 1 / 4
# 1
# D, [2011-03-07T10:55:48.015350 #92103] DEBUG -- : l.rb:5:in `<main>' 2 / 4
# 2
# D, [2011-03-07T10:55:48.015722 #92103] DEBUG -- : l.rb:5:in `<main>' 3 / 4
# 3
# D, [2011-03-07T10:55:48.015977 #92103] DEBUG -- : l.rb:5:in `<main>' 4 / 4
# 4

Copyright © 2011 hitode909. See LICENSE.txt for further details.