class UU::LoggerFluent::Formatter

Constants

DEFAULT_TAG
PATHS

Attributes

tag[RW]
context[R]

Public Class Methods

new(context) click to toggle source
# File lib/uu/logger_fluent.rb, line 14
def initialize(context)
  @context = context
end

Public Instance Methods

call(severity, msg) click to toggle source
# File lib/uu/logger_fluent.rb, line 20
def call(severity, msg)
  [self.class.tag, {
    log_level: severity,
    **metadata,
    **@context.context,
    **(msg.is_a?(Hash) ? msg : { message: msg }),
  }]
end
find_location() click to toggle source
# File lib/uu/logger_fluent.rb, line 45
def find_location
  caller_locations.find do |location_|
    location_.path != __FILE__ &&
      PATHS.none? { |path| location_.path.end_with?(path) }
  end
end
metadata() click to toggle source
# File lib/uu/logger_fluent.rb, line 29
def metadata
  location = find_location
  {
    filename: File.basename(location.path),
    method: location.label,
    lineno: location.lineno,
  }
end