lib/memolog.rb in memolog-0.5.1 vs lib/memolog.rb in memolog-0.5.2

- old
+ new

@@ -29,27 +29,23 @@ def extend_logger(other_logger) other_logger.extend(Memolog::LoggerExtension) end - def logger - Thread.current[:memolog_logger] ||= Logger.new(nil, formatter: config.formatter) - end - - def logdevs - Thread.current[:memolog_logdevs] ||= [] - end - def run logdevs.push(StringIO.new) logger.instance_variable_set(:@logdev, logdevs.last) yield ensure logdevs.pop unless config.debug end + def log(*args, &block) + logger.log(*args, &block) + end + def dump(parse_json: false) return if logdevs.empty? beginning = logdevs.last.string.length - config.log_size_limit beginning = 0 if beginning.negative? @@ -57,7 +53,21 @@ dump = logdevs.last.string.slice(beginning, config.log_size_limit).presence dump && parse_json ? JSON.parse(dump) : dump rescue JSON::ParserError dump + end + + private + + def logger + storage[:memolog_logger] ||= Logger.new(nil, formatter: config.formatter) + end + + def logdevs + storage[:memolog_logdevs] ||= [] + end + + def storage + config.isolation_level == :fiber ? Fiber : Thread.current end end