Class: Logger
- Inherits:
-
Object
- Object
- Logger
- Defined in:
- activesupport/lib/active_support/core_ext/logger.rb,
activesupport/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: SimpleFormatter
Instance Attribute Summary (collapse)
-
- (Object) formatter
Get the current formatter.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) datetime_format
Get the logging datetime format.
-
- (Object) datetime_format=(datetime_format)
Logging date-time format (string passed to strftime).
- - (Object) format_datetime(datetime)
- - (Object) format_message(severity, timestamp, msg, progname)
- - (Object) msg2str(msg)
- - (Object) old_datetime_format
- - (Object) old_datetime_format=
- - (Object) old_format_datetime
- - (Object) old_formatter
- - (Object) old_msg2str
-
- (Object) silence(temporary_level = Logger::ERROR)
Silences the logger for the duration of the block.
Instance Attribute Details
- (Object) formatter
Get the current formatter. The default formatter is a SimpleFormatter which only displays the log message
71 72 73 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 71 def formatter @formatter ||= SimpleFormatter.new end |
Class Method Details
+ (Object) define_around_helper(level)
:nodoc:
5 6 7 8 9 10 11 12 13 14 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 5 def self.define_around_helper(level) module_eval <<-end_eval, __FILE__, __LINE__ + 1 def around_#{level}(before_message, after_message, &block) # def around_debug(before_message, after_message, &block) self.#{level}(before_message) # self.debug(before_message) return_value = block.call(self) # return_value = block.call(self) self.#{level}(after_message) # self.debug(after_message) return return_value # return return_value end # end end_eval end |
Instance Method Details
- (Object) datetime_format
Get the logging datetime format. Returns nil if the formatter does not support datetime formatting.
64 65 66 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 64 def datetime_format formatter.datetime_format if formatter.respond_to?(:datetime_format) end |
- (Object) datetime_format=(datetime_format)
Logging date-time format (string passed to strftime). Ignored if the formatter does not respond to datetime_format=.
57 58 59 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 57 def datetime_format=(datetime_format) formatter.datetime_format = datetime_format if formatter.respond_to?(:datetime_format=) end |
- (Object) format_datetime(datetime)
103 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 103 def format_datetime(datetime) datetime end |
- (Object) format_message(severity, timestamp, msg, progname)
91 92 93 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 91 def (severity, , msg, progname) formatter.call(severity, , progname, msg) end |
- (Object) msg2str(msg)
106 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 106 def msg2str(msg) msg end |
- (Object) old_datetime_format
61 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 61 alias :old_datetime_format :datetime_format |
- (Object) old_datetime_format=
54 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 54 alias :old_datetime_format= :datetime_format= |
- (Object) old_format_datetime
102 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 102 alias old_format_datetime format_datetime |
- (Object) old_formatter
68 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 68 alias :old_formatter :formatter |
- (Object) old_msg2str
105 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 105 alias old_msg2str msg2str |
- (Object) silence(temporary_level = Logger::ERROR)
Silences the logger for the duration of the block.
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'activesupport/lib/active_support/core_ext/logger.rb', line 41 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 |