Class: Logger
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
Direct Known Subclasses
Defined Under Namespace
Classes: Formatter, SimpleFormatter
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Get the current formatter.
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
52 53 54 |
# File 'lib/inactive_support/clean_logger.rb', line 52 def formatter @formatter ||= SimpleFormatter.new end |
Instance Method Details
#datetime_format ⇒ Object
Get the logging datetime format. Returns nil if the formatter does not support datetime formatting.
45 46 47 |
# File 'lib/inactive_support/clean_logger.rb', line 45 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=.
38 39 40 |
# File 'lib/inactive_support/clean_logger.rb', line 38 def datetime_format=(datetime_format) formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=) end |
#old_datetime_format ⇒ Object
42 |
# File 'lib/inactive_support/clean_logger.rb', line 42 alias :old_datetime_format :datetime_format |
#old_datetime_format= ⇒ Object
35 |
# File 'lib/inactive_support/clean_logger.rb', line 35 alias :old_datetime_format= :datetime_format= |
#old_formatter ⇒ Object
49 |
# File 'lib/inactive_support/clean_logger.rb', line 49 alias :old_formatter :formatter |
#silence(temporary_level = Logger::ERROR) ⇒ Object
Silences the logger for the duration of the block.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/inactive_support/clean_logger.rb', line 22 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 |