module SemanticLogger::Formatters
Public Class Methods
factory(formatter)
click to toggle source
Return formatter that responds to call.
Supports formatter supplied as:
-
Symbol
-
Hash ( Symbol => { options })
-
Instance of any of
SemanticLogger::Formatters
-
Proc
-
Any object that responds to :call
# File lib/semantic_logger/formatters.rb, line 22 def self.factory(formatter) if formatter.is_a?(Symbol) SemanticLogger::Utils.constantize_symbol(formatter, "SemanticLogger::Formatters").new elsif formatter.is_a?(Hash) && formatter.size.positive? fmt, options = formatter.first SemanticLogger::Utils.constantize_symbol(fmt.to_sym, "SemanticLogger::Formatters").new(**options) elsif formatter.respond_to?(:call) formatter else raise(ArgumentError, "Unknown formatter: #{formatter.inspect}") end end