Class: Logger
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb,
lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb
Overview
Extensions to the built in Ruby logger.
If you want to use the default log formatter as defined in the Ruby core, then you will need to set the formatter for the logger as in:
logger.formatter = Formatter.new
You can then specify the datetime format, for example:
logger.datetime_format = "%Y-%m-%d"
Note: This logger is deprecated in favor of ActiveSupport::BufferedLogger
Defined Under Namespace
Classes: Formatter, SimpleFormatter
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Get the current formatter.
Class Method Summary collapse
Instance Method Summary collapse
-
#datetime_format ⇒ Object
Get the logging datetime format.
-
#datetime_format=(datetime_format) ⇒ Object
Logging date-time format (string passed to
strftime
). - #old_datetime_format ⇒ Object
- #old_datetime_format= ⇒ Object
- #old_formatter ⇒ Object
-
#silence(temporary_level = Logger::ERROR) ⇒ Object
Silences the logger for the duration of the block.
Instance Attribute Details
#formatter ⇒ Object
Get the current formatter. The default formatter is a SimpleFormatter which only displays the log message
68 69 70 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 68 def formatter @formatter ||= SimpleFormatter.new end |
Class Method Details
.define_around_helper(level) ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 4 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 |
Instance Method Details
#datetime_format ⇒ Object
Get the logging datetime format. Returns nil if the formatter does not support datetime formatting.
61 62 63 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 61 def datetime_format formatter.datetime_format if formatter.respond_to?(:datetime_format) end |
#datetime_format=(datetime_format) ⇒ Object
Logging date-time format (string passed to strftime
). Ignored if the formatter does not respond to datetime_format=.
54 55 56 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 54 def datetime_format=(datetime_format) formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=) end |
#old_datetime_format ⇒ Object
58 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 58 alias :old_datetime_format :datetime_format |
#old_datetime_format= ⇒ Object
51 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 51 alias :old_datetime_format= :datetime_format= |
#old_formatter ⇒ Object
65 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 65 alias :old_formatter :formatter |
#silence(temporary_level = Logger::ERROR) ⇒ Object
Silences the logger for the duration of the block.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/core_ext/logger.rb', line 38 def silence(temporary_level = Logger::ERROR) if silencer begin old_logger_level, self.level = level, temporary_level yield self ensure self.level = old_logger_level end else yield self end end |