Sha256: 024b2f22f702809828b0bf44dc3d26582d591120390a6f5f45f4b5c487557634

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

# Lamian is an in-memory logger, which content could be released
# for error messages.
# It is designed to work in pair with `exception_notification` gem inside
# rails aplications
module Lamian
  autoload :VERSION, "lamian/version"
  autoload :Config, "lamian/config"
  autoload :Logger, "lamian/logger"
  autoload :LoggerExtension, "lamian/logger_extension"
  autoload :Middleware, "lamian/middleware"

  require "lamian/engine"

  class << self
    # Yields curent configuration if block given
    # @example
    #   Lamian.configure do |config|
    #     config.formatter = MyFormatter.new
    #   end
    # @yield [config] current configuration
    # @yieldparam config [Lamian::Config]
    # @return [Lamian::Config] current configuration
    def configure
      @config ||= Config.new
      yield(@config) if block_given?
      @config
    end
    alias config configure

    # Extends logger instance to tee it's output to Lamian logger
    # @param other_logger [Logger] logger to extend
    def extend_logger(other_logger)
      other_logger.extend(Lamian::LoggerExtension)
    end

    # @api private
    # Gives access to current logger
    # @return [Lamian::Logger] current logger
    def logger
      Lamian::Logger.current
    end

    # Collects logs sent inside block
    def run
      logger.run { yield }
    end

    # Dumps log collected in this run
    # @option format [Symbol]
    #   requested format of log. At this point, returns raw log if falsey
    #   or log without controll sequences (such as '[23m') if truthy
    #   value given (for now)
    # @return formatted log (String by default)
    def dump(format: nil)
      logger.dump(format: format)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lamian-1.0.1 lib/lamian.rb
lamian-1.0.0alpha lib/lamian.rb