lib/lamian.rb in lamian-0.3.3 vs lib/lamian.rb in lamian-1.0.0alpha
- old
+ new
@@ -1,35 +1,59 @@
# 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'
+ autoload :VERSION, "lamian/version"
+ autoload :Config, "lamian/config"
+ autoload :Logger, "lamian/logger"
+ autoload :LoggerExtension, "lamian/logger_extension"
+ autoload :Middleware, "lamian/middleware"
- require 'lamian/engine'
+ 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