Class: Vigilant::Rails::Logger
- Inherits:
-
ActiveSupport::Logger
- Object
- ActiveSupport::Logger
- Vigilant::Rails::Logger
- Includes:
- ActiveSupport::LoggerSilence, ActiveSupport::LoggerThreadSafeLevel, LoggerSilence
- Defined in:
- lib/vigilant-ruby/rails/logger.rb
Overview
A wrapper that delegates Rails-style logging calls to Vigilant::Logger
Constant Summary collapse
- SEVERITY_MAP =
{ ::Logger::DEBUG => Vigilant::DEBUG, ::Logger::INFO => Vigilant::INFO, ::Logger::WARN => Vigilant::WARNING, ::Logger::ERROR => Vigilant::ERROR, ::Logger::FATAL => Vigilant::ERROR, ::Logger::UNKNOWN => Vigilant::ERROR }.freeze
Instance Attribute Summary collapse
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Instance Method Summary collapse
- #add(severity, message_or_block = nil, progname = nil) ⇒ Object
- #broadcast_to(*io_devices_and_loggers) ⇒ Object
- #broadcasts ⇒ Object
- #close ⇒ Object
- #current_tags ⇒ Object
- #datetime_format ⇒ Object
- #datetime_format=(_format) ⇒ Object
- #debug(progname = nil, &block) ⇒ Object
- #error(progname = nil, &block) ⇒ Object
- #fatal(progname = nil, &block) ⇒ Object
- #flush ⇒ Object
- #info(progname = nil, &block) ⇒ Object
-
#initialize(name: Vigilant.configuration.name, endpoint: Vigilant.configuration.endpoint, token: Vigilant.configuration.token, insecure: Vigilant.configuration.insecure, passthrough: Vigilant.configuration.passthrough) ⇒ Logger
constructor
A new instance of Logger.
- #kind_of?(klass) ⇒ Boolean (also: #is_a?)
- #pop_tags(amount = 1) ⇒ Object
- #push_tags(*tags) ⇒ Object
- #reopen(_device = nil) ⇒ Object
- #silence(temporary_level = ::Logger::ERROR) ⇒ Object
- #stop_broadcasting_to(io_device_or_logger) ⇒ Object
- #tagged(*tags) ⇒ Object
- #unknown(progname = nil, &block) ⇒ Object
- #warn(progname = nil, &block) ⇒ Object
Constructor Details
#initialize(name: Vigilant.configuration.name, endpoint: Vigilant.configuration.endpoint, token: Vigilant.configuration.token, insecure: Vigilant.configuration.insecure, passthrough: Vigilant.configuration.passthrough) ⇒ Logger
Returns a new instance of Logger.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 27 def initialize(name: Vigilant.configuration.name, endpoint: Vigilant.configuration.endpoint, token: Vigilant.configuration.token, insecure: Vigilant.configuration.insecure, passthrough: Vigilant.configuration.passthrough) super(nil) @vigilant_logger = Vigilant::Logger.new( endpoint: endpoint, token: token, name: name, insecure: insecure, passthrough: passthrough ) at_exit { close } self.level = ::Logger::DEBUG @tags = [] @extra_loggers = [] end |
Instance Attribute Details
#formatter ⇒ Object
Returns the value of attribute formatter.
173 174 175 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 173 def formatter @formatter end |
Instance Method Details
#add(severity, message_or_block = nil, progname = nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 107 def add(severity, = nil, progname = nil) return true if severity < level msg = if .respond_to?(:call) .call.to_s else ( || progname).to_s end.strip vigilant_severity = SEVERITY_MAP.fetch(severity, Vigilant::ERROR) log_to_vigilant(vigilant_severity, msg) @extra_loggers.each { |logger| logger.add(severity, msg, progname) } true end |
#broadcast_to(*io_devices_and_loggers) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 60 def broadcast_to(*io_devices_and_loggers) io_devices_and_loggers.each do |io_device_or_logger| extra_logger = if io_device_or_logger.is_a?(::Logger) io_device_or_logger else ::ActiveSupport::Logger.new(io_device_or_logger) end @extra_loggers << extra_logger end end |
#broadcasts ⇒ Object
56 57 58 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 56 def broadcasts [self] + @extra_loggers end |
#close ⇒ Object
161 162 163 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 161 def close @vigilant_logger.shutdown if @vigilant_logger.respond_to?(:shutdown) end |
#current_tags ⇒ Object
139 140 141 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 139 def @tags end |
#datetime_format ⇒ Object
169 170 171 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 169 def datetime_format nil end |
#datetime_format=(_format) ⇒ Object
165 166 167 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 165 def datetime_format=(_format) nil end |
#debug(progname = nil, &block) ⇒ Object
83 84 85 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 83 def debug(progname = nil, &block) add(::Logger::DEBUG, block, progname) end |
#error(progname = nil, &block) ⇒ Object
95 96 97 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 95 def error(progname = nil, &block) add(::Logger::ERROR, block, progname) end |
#fatal(progname = nil, &block) ⇒ Object
99 100 101 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 99 def fatal(progname = nil, &block) add(::Logger::FATAL, block, progname) end |
#flush ⇒ Object
151 152 153 154 155 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 151 def flush @vigilant_logger.flush if @vigilant_logger.respond_to?(:flush) rescue StandardError nil end |
#info(progname = nil, &block) ⇒ Object
87 88 89 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 87 def info(progname = nil, &block) add(::Logger::INFO, block, progname) end |
#kind_of?(klass) ⇒ Boolean Also known as: is_a?
49 50 51 52 53 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 49 def kind_of?(klass) return true if defined?(::ActiveSupport::BroadcastLogger) && klass == ::ActiveSupport::BroadcastLogger super(klass) end |
#pop_tags(amount = 1) ⇒ Object
135 136 137 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 135 def (amount = 1) @tags.pop(amount) end |
#push_tags(*tags) ⇒ Object
131 132 133 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 131 def (*) @tags.concat() end |
#reopen(_device = nil) ⇒ Object
157 158 159 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 157 def reopen(_device = nil) nil end |
#silence(temporary_level = ::Logger::ERROR) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 143 def silence(temporary_level = ::Logger::ERROR) old_level = level self.level = temporary_level yield self ensure self.level = old_level end |
#stop_broadcasting_to(io_device_or_logger) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 72 def stop_broadcasting_to(io_device_or_logger) if io_device_or_logger.is_a?(::Logger) @extra_loggers.delete(io_device_or_logger) else @extra_loggers.reject! do |logger| defined?(::ActiveSupport::Logger) && ::ActiveSupport::Logger.logger_outputs_to?(logger, io_device_or_logger) end end end |
#tagged(*tags) ⇒ Object
124 125 126 127 128 129 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 124 def tagged(*) (*) yield self ensure (.size) end |
#unknown(progname = nil, &block) ⇒ Object
103 104 105 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 103 def unknown(progname = nil, &block) add(::Logger::UNKNOWN, block, progname) end |
#warn(progname = nil, &block) ⇒ Object
91 92 93 |
# File 'lib/vigilant-ruby/rails/logger.rb', line 91 def warn(progname = nil, &block) add(::Logger::WARN, block, progname) end |