lib/loggr/adapter/base.rb in loggr-1.0.0 vs lib/loggr/adapter/base.rb in loggr-1.1.0

- old
+ new

@@ -1,35 +1,36 @@ require 'loggr/adapter/abstract' -require 'logger' +require 'loggr/support/annotations' module Loggr module Adapter - + # Default backend which is backed Rubys Stdlib Logger. # class BaseAdapter < AbstractAdapter - - # + # + # def logger(name, options = {}) name = normalize_name(name) @loggers ||= {} @loggers[name] ||= build_new_logger(name, options) end - + protected # Constructs a new logger instance for the supplied options, is called # by `#loggers` when no logger with this name already exists - instead of # creating a new logger... # def build_new_logger(name, options = {}) - ::Logger.new(options[:to] || "#{name.to_s.gsub(/[:\s\/]+/, '_')}.log").tap do |logger| + logger = ::Logger.new(options[:to] || "#{name.to_s.gsub(/[:\s\/]+/, '_')}.log").tap do |logger| logger.level = options[:level] || Logger::INFO logger.progname = name - end + end + Loggr::Support::Annotations.enhance(logger) end - + # Because we should also allow using class names, or objects # to construct new loggers (like in SLF4J), it makes sense to # have a method which normalizes some input, be it a string or # whatnot to convert to an appropriate name. # @@ -43,12 +44,12 @@ case name when Symbol then name.to_s when Module then name.name.to_s else name.class.name.to_s end - end + end end - + # Okay, basically a singleton thus create instance Base = BaseAdapter.new end end