class Flnt::Logger

Public Class Methods

new(init_tag) click to toggle source
# File lib/flnt/logger.rb, line 21
def initialize(init_tag)
  @tag = init_tag
end

Public Instance Methods

emit!(arg, tag: nil) click to toggle source
# File lib/flnt/logger.rb, line 50
def emit!(arg, tag: nil)
  ::Fluent::Logger.post((tag || @tag), to_info!(arg))
end
method_missing(name, *args) click to toggle source
Calls superclass method
# File lib/flnt/logger.rb, line 25
def method_missing(name, *args)
  return super if name.to_s =~ /(!|\?)$/

  if !args.empty?
    emit! args.first, tag: [@tag, name.to_s].join('.')
  else
    @tag << "." << name.to_s
  end

  return self
end
tee!(logger_or_path) click to toggle source
# File lib/flnt/logger.rb, line 54
def tee!(logger_or_path)
  new_self = TeeableLogger.new(@tag)
  case
  when logger_or_path.respond_to?(:info)
    new_self.teed_logger = logger_or_path
  when [::String, ::Pathname].include?(logger_or_path.class)
    l = ::Logger.new(logger_or_path)
    new_self.teed_logger = l
  end
  new_self
end

Private Instance Methods

to_info!(arg) click to toggle source
# File lib/flnt/logger.rb, line 67
def to_info!(arg)
  info = {}
  case arg
  when ::Hash
    info.merge! arg
  when ::String
    info[:message] = arg
  when ::Exception
    info[:error_class] = arg.class
    info[:message]     = arg.message
    info[:backtrace]   = arg.backtrace if arg.backtrace
  else
    info[:info] = arg
  end

  info
end