Sha256: b0b806b39c0525dd0223712baa9fdb33cfe821c378f00d510d1198cc1109ed2a

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

module Slf4r
  class AbstractLoggerFacade

    protected

    def format(exception)
      (": #{exception.message}:\n\t#{exception.backtrace.join("\n\t") if exception.backtrace }") if exception
    end

    def _debug(msg)
      raise NotImplementedError
    end

    def _info(msg)
      raise NotImplementedError
    end

    def _warn(msg)
      raise NotImplementedError
    end

    def _error(msg)
      raise NotImplementedError
    end

    def _fatal(msg)
      raise NotImplementedError
    end

    public

    attr_reader :name

    def initialize(name)
      @name = name
    end

    def debug?
      raise NotImplementedError
    end

    def debug(msg = nil, exception = nil)
      if(debug?)
        msg, exception = yield if block_given?
        _debug("#{msg}#{format(exception)}")
      end
    end

    def info?
      raise NotImplementedError
    end

    def info(msg = nil, exception = nil)
      if(info?)
        msg, exception = yield if block_given?
        _info("#{msg}#{format(exception)}")
      end
    end

    def warn?
      raise NotImplementedError
    end

    def warn(msg = nil, exception = nil)
      if(warn?)
        msg, exception = yield if block_given?
        _warn("#{msg}#{format(exception)}")
      end
    end

    def error?
      raise NotImplementedError
    end

    def error(msg = nil, exception = nil)
      if(error?)
        msg, exception = yield if block_given?
        _error("#{msg}#{format(exception)}")
      end
    end

    def fatal?
      raise NotImplementedError
    end

    def fatal(msg = nil, exception = nil)
      if(fatal?)
        msg, exception = yield if block_given?
        _fatal("#{msg}#{format(exception)}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
slf4r-0.4.0 lib/slf4r/abstract_logger_facade.rb
slf4r-0.3.3 lib/slf4r/abstract_logger_facade.rb
slf4r-0.3.2 lib/slf4r/abstract_logger_facade.rb
slf4r-0.3.1 lib/slf4r/abstract_logger_facade.rb