Class: FluentLoggerRails::Logger

Inherits:
ActiveSupport::Logger
  • Object
show all
Defined in:
lib/fluent_logger_rails/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(logger, path:, level:) ⇒ Logger

Returns a new instance of Logger.



6
7
8
9
10
11
# File 'lib/fluent_logger_rails/logger.rb', line 6

def initialize(logger, path:, level:)
  @level = SEV_LABEL.index(level.to_s.upcase)
  @path = path
  @logger = logger
  after_initialize if respond_to?(:after_initialize) && ActiveSupport::VERSION::MAJOR < 6
end

Instance Method Details

#add(severity, message = nil, progname = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fluent_logger_rails/logger.rb', line 13

def add(severity, message = nil, progname = nil)
  return true if severity < @level

  message = (block_given? ? yield : progname) if message.blank?
  return true if message.blank?

  message = format_message(severity, Time.zone.now, progname, message)

  @logger.post(@path, message)
  true
end

#closeObject



25
26
27
# File 'lib/fluent_logger_rails/logger.rb', line 25

def close
  @logger.close
end

#flushObject



35
36
37
38
# File 'lib/fluent_logger_rails/logger.rb', line 35

def flush
  clear_tags!
  super if defined?(super)
end

#tagged(*tags) ⇒ Object



31
32
33
# File 'lib/fluent_logger_rails/logger.rb', line 31

def tagged(*tags)
  formatter.tagged(*tags) { yield self }
end