diff options
author | Michael Koziarski <michael@koziarski.com> | 2006-02-26 19:48:33 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2006-02-26 19:48:33 +0000 |
commit | 3cfbb4f374cee2d193b80d4cd373e3fd05997027 (patch) | |
tree | 59cc4082fca85adbf8726b437180e1723cbe2c24 /activesupport | |
parent | 3d1b51b4411ffe8de92d997b824637f9eaf47bb1 (diff) | |
download | rails-3cfbb4f374cee2d193b80d4cd373e3fd05997027.tar.gz rails-3cfbb4f374cee2d193b80d4cd373e3fd05997027.tar.bz2 rails-3cfbb4f374cee2d193b80d4cd373e3fd05997027.zip |
Add around methods to Logger. Closes #3809
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3670 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/logger.rb | 16 |
2 files changed, 21 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index b68e2cad15..d8fa10ce8b 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,10 @@ *SVN* +* Add 'around' methods to Logger, to make it easy to log before and after messages for a given block as requested in #3809. [Michael Koziarski] Example: + + logger.around_info("Start rendering component (#{options.inspect}): ", + "\n\nEnd of component rendering") { yield } + * Added Time#beginning_of_quarter #3607 [cohen.jeff@gmail.com] * Fix Object.subclasses_of to only return currently defined objects [Jonathan Viney <jonathan@bluewire.net.nz>] diff --git a/activesupport/lib/active_support/core_ext/logger.rb b/activesupport/lib/active_support/core_ext/logger.rb new file mode 100644 index 0000000000..9c1fd274ac --- /dev/null +++ b/activesupport/lib/active_support/core_ext/logger.rb @@ -0,0 +1,16 @@ +# Adds the 'around_level' method to Logger. + +class Logger + def self.define_around_helper(level) + module_eval <<-end_eval + def around_#{level}(before_message, after_message, &block) + self.#{level}(before_message) + return_value = block.call(self) + self.#{level}(after_message) + return return_value + end + end_eval + end + [:debug, :info, :error, :fatal].each {|level| define_around_helper(level) } + +end
\ No newline at end of file |