Module: Sidekiq::LoggingUtils
- Included in:
- Logger
- Defined in:
- lib/sidekiq/logger.rb
Constant Summary collapse
- LEVELS =
{ "debug" => 0, "info" => 1, "warn" => 2, "error" => 3, "fatal" => 4, }
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.
- #debug? ⇒ Boolean
- #error? ⇒ Boolean
- #fatal? ⇒ Boolean
- #info? ⇒ Boolean
- #level ⇒ Object
- #local_level ⇒ Object
- #local_level=(level) ⇒ Object
-
#log_at(level) ⇒ Object
Change the thread-local level for the duration of the given block.
- #warn? ⇒ Boolean
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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sidekiq/logger.rb', line 85 def add(severity, = nil, progname = nil, &block) 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 |
#debug? ⇒ Boolean
33 34 35 |
# File 'lib/sidekiq/logger.rb', line 33 def debug? level >= 0 end |
#error? ⇒ Boolean
45 46 47 |
# File 'lib/sidekiq/logger.rb', line 45 def error? level >= 3 end |
#fatal? ⇒ Boolean
49 50 51 |
# File 'lib/sidekiq/logger.rb', line 49 def fatal? level >= 4 end |
#info? ⇒ Boolean
37 38 39 |
# File 'lib/sidekiq/logger.rb', line 37 def info? level >= 1 end |
#level ⇒ Object
70 71 72 |
# File 'lib/sidekiq/logger.rb', line 70 def level local_level || super end |
#local_level ⇒ Object
53 54 55 |
# File 'lib/sidekiq/logger.rb', line 53 def local_level Thread.current[:sidekiq_log_level] end |
#local_level=(level) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sidekiq/logger.rb', line 57 def local_level=(level) case level when Integer Thread.current[:sidekiq_log_level] = level when Symbol, String Thread.current[:sidekiq_log_level] = LEVELS[level.to_s] when nil Thread.current[:sidekiq_log_level] = nil else raise ArgumentError, "Invalid log level: #{level.inspect}" end end |
#log_at(level) ⇒ Object
Change the thread-local level for the duration of the given block.
75 76 77 78 79 80 81 |
# File 'lib/sidekiq/logger.rb', line 75 def log_at(level) old_local_level = local_level self.local_level = level yield ensure self.local_level = old_local_level end |
#warn? ⇒ Boolean
41 42 43 |
# File 'lib/sidekiq/logger.rb', line 41 def warn? level >= 2 end |