lib/memolog.rb in memolog-0.1.0 vs lib/memolog.rb in memolog-0.2.0

- old
+ new

@@ -1,55 +1,58 @@ # frozen_string_literal: true require "logger" require "securerandom" +require "stringio" +require "memolog/version" +require "memolog/config" +require "memolog/extension" +require "memolog/formatter" +require "memolog/init" +require "memolog/middleware" +require "memolog/sentry_scope_extension" +require "memolog/sentry_sidekiq_middleware" + module Memolog extend self - autoload :VERSION, "memolog/version" - autoload :Config, "memolog/config" - autoload :Extension, "memolog/extension" - autoload :Formatter, "memolog/formatter" - autoload :Middleware, "memolog/middleware" - autoload :SentryScopeExtension, "memolog/sentry_scope_extension" - autoload :SentrySidekiqMiddleware, "memolog/sentry_sidekiq_middleware" + attr_accessor :config, :logdevs - attr_accessor :debug, :logdevs + @config = Memolog::Config.new + @logdevs = [] - self.debug = false - self.logdevs = [] - def configure - @config ||= Memolog::Config.new - yield(@config) if block_given? - @config + yield(config) if block_given? end - alias config configure + def init! + Memolog::Init.new.call + end + def extend_logger(other_logger) other_logger.extend(Memolog::Extension) other_logger.formatter = config.formatter end - def logger - Thread.current[:memolog_logger] ||= Logger.new(nil, formatter: config.formatter) - end - def uuid Thread.current[:memolog_uuid] end + def logger + Thread.current[:memolog_logger] ||= Logger.new(nil, formatter: config.formatter) + end + def run - Thread.current[:memolog_uuid] = Memolog.config.uuid_callable.call + Thread.current[:memolog_uuid] = config.uuid_callable.call logdevs.push(StringIO.new) logger.instance_variable_set(:@logdev, logdevs.last) yield ensure - logdevs.pop unless debug + logdevs.pop unless config.debug end def dump return if logdevs.empty? @@ -57,7 +60,5 @@ beginning = 0 if beginning.negative? logdevs.last.string.slice(beginning, config.log_size_limit) end end - -require "memolog/init"