Sha256: 43e650ec941488fa0e079613f1f5587b25144082fda7aa4c03f4f6cffacc3b7a
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
require 'inflecto' require 'logger' require 'json' require_relative 'logasm/adapters' require_relative 'logasm/utils' require_relative 'logasm/null_logger' LOG_LEVEL_QUERY_METHODS = [:debug?, :info?, :warn?, :error?, :fatal?] class Logasm def self.build(service_name, loggers_config) loggers_config ||= {stdout: nil} adapters = loggers_config.map do |type, arguments| Adapters.get(type.to_s, service_name, arguments || {}) end new(adapters) end def initialize(adapters) @adapters = adapters end def debug(*args) log :debug, *args end def info(*args) log :info, *args end def warn(*args) log :warn, *args end def error(*args) log :error, *args end def fatal(*args) log :fatal, *args end LOG_LEVEL_QUERY_METHODS.each do |method| define_method(method) do @adapters.any? {|adapter| adapter.public_send(method) } end end private def log(level, *args) data = parse_log_data(*args) @adapters.each do |adapter| adapter.log(level, data) end end def parse_log_data(message, metadata = {}) return message if message.is_a?(Hash) (metadata || {}).merge(message: message) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
logasm-0.2.6 | lib/logasm.rb |