Module: ActiveSupport::LoggerThreadSafeLevel
- Extended by:
- Concern
- Defined in:
- lib/active_support/logger_thread_safe_level.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Redefined to check severity against #level, and thus the thread-local level, rather than @level.
- #level ⇒ Object
- #local_level ⇒ Object
- #local_level=(level) ⇒ Object
- #local_log_id ⇒ Object
-
#log_at(level) ⇒ Object
Change the thread-local level for the duration of the given block.
Methods included from Concern
append_features, class_methods, extended, included, prepend_features, prepended
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
Redefined to check severity against #level, and thus the thread-local level, rather than @level. FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 59 def add(severity, = nil, progname = nil, &block) #:nodoc: severity ||= UNKNOWN progname ||= @progname return true if @logdev.nil? || severity < level if .nil? if block_given? = yield else = progname progname = @progname end end @logdev.write \ (format_severity(severity), Time.now, progname, ) end |
#level ⇒ Object
45 46 47 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 45 def level local_level || super end |
#local_level ⇒ Object
28 29 30 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 28 def local_level self.class.local_levels[local_log_id] end |
#local_level=(level) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 32 def local_level=(level) case level when Integer self.class.local_levels[local_log_id] = level when Symbol self.class.local_levels[local_log_id] = Logger::Severity.const_get(level.to_s.upcase) when nil self.class.local_levels.delete(local_log_id) else raise ArgumentError, "Invalid log level: #{level.inspect}" end end |
#local_log_id ⇒ Object
24 25 26 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 24 def local_log_id Fiber.current.__id__ end |
#log_at(level) ⇒ Object
Change the thread-local level for the duration of the given block.
50 51 52 53 54 55 |
# File 'lib/active_support/logger_thread_safe_level.rb', line 50 def log_at(level) old_local_level, self.local_level = local_level, level yield ensure self.local_level = old_local_level end |