Class: RailsLokiExporter::InterceptingLogger
- Inherits:
-
ActiveSupport::Logger
- Object
- ActiveSupport::Logger
- RailsLokiExporter::InterceptingLogger
- Defined in:
- lib/rails_loki_exporter/intercepting_logger.rb
Constant Summary collapse
- SEVERITY_NAMES =
%w(DEBUG INFO WARN ERROR FATAL ANY).freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
- #broadcast_to(console) ⇒ Object
-
#initialize(intercept_logs: false) ⇒ InterceptingLogger
constructor
A new instance of InterceptingLogger.
Constructor Details
#initialize(intercept_logs: false) ⇒ InterceptingLogger
Returns a new instance of InterceptingLogger.
13 14 15 16 17 18 |
# File 'lib/rails_loki_exporter/intercepting_logger.rb', line 13 def initialize(intercept_logs: false) @intercept_logs = intercept_logs @log = "" super(STDOUT) self.level = Logger::DEBUG end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/rails_loki_exporter/intercepting_logger.rb', line 9 def client @client end |
Instance Method Details
#add(severity, message = nil, progname = nil, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rails_loki_exporter/intercepting_logger.rb', line 20 def add(severity, = nil, progname = nil, &block) severity_name = severity_name(severity) = if .nil? if block_given? = yield else = progname progname = @progname end end if @intercept_logs && !.nil? = (severity_name, Time.now, progname, ) client.send_log() if client end super(severity, , progname, &block) end |
#broadcast_to(console) ⇒ Object
40 41 42 |
# File 'lib/rails_loki_exporter/intercepting_logger.rb', line 40 def broadcast_to(console) client.send_log(@log) if client end |