class SemanticLogger::Appender::Wrapper
def close
Close underlying log
def close @logger.close if @logger.respond_to?(:close) end
def flush
Flush all pending logs to disk.
def flush @logger.flush if @logger.respond_to?(:flush) end
def initialize(logger:, **args, &block)
logger.info('Hello World', some: :payload)
logger = SemanticLogger['test']
SemanticLogger.add_appender(logger: ruby_logger)
ruby_logger = Logger.new($stdout)
require 'semantic_logger'
require 'logger'
Ruby Logger
The Proc must return true or false.
Proc: Only include log messages where the supplied Proc returns true
regular expression. All other messages will be ignored.
RegExp: Only include log messages where the class name matches the supplied.
filter: [Regexp|Proc]
Default: Use the built-in formatter (See: #call)
the output from this appender
An instance of a class that implements #call, or a Proc to be used to format
formatter: [Object|Proc]
Default: SemanticLogger.default_level
Override the log level for this appender.
level: [:trace | :debug | :info | :warn | :error | :fatal]
Instance of an existing logger conforming to the Ruby Logger methods.
logger: [Object]
Parameters
Forward all logging calls to the supplied logging instance.
def initialize(logger:, **args, &block) @logger = logger # Check if the custom appender responds to all the log levels. For example Ruby ::Logger does_not_implement = LEVELS[1..-1].find { |i| !@logger.respond_to?(i) } if does_not_implement raise(ArgumentError, "Supplied logger does not implement:#{does_not_implement}. It must implement all of #{LEVELS[1..-1].inspect}") end super(**args, &block) end
def log(log)
trace entries are mapped to debug since :trace is not supported by the
Pass log calls to the underlying Rails, log4j or Ruby logger
def log(log) level = log.level == :trace ? :debug : log.level @logger.send(level, formatter.call(log, self)) true end