lib/memolog.rb in memolog-0.3.5 vs lib/memolog.rb in memolog-0.4.0
- old
+ new
@@ -1,14 +1,14 @@
# frozen_string_literal: true
require "logger"
require "securerandom"
require "stringio"
+require "json"
require "memolog/version"
require "memolog/config"
-require "memolog/formatter"
require "memolog/init"
require "memolog/logger_extension"
require "memolog/rails_middleware"
require "memolog/sentry_extension"
require "memolog/sidekiq_middleware"
@@ -28,28 +28,21 @@
Memolog::Init.init_middlewares!
end
def extend_logger(other_logger)
other_logger.extend(Memolog::LoggerExtension)
- other_logger.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 logdevs
Thread.current[:memolog_logdevs] ||= []
end
def run
- Thread.current[:memolog_uuid] = config.uuid_callable.call
-
logdevs.push(StringIO.new)
logger.instance_variable_set(:@logdev, logdevs.last)
yield
ensure
@@ -60,8 +53,12 @@
return if logdevs.empty?
beginning = logdevs.last.string.length - config.log_size_limit
beginning = 0 if beginning.negative?
- logdevs.last.string.slice(beginning, config.log_size_limit).presence
+ dump = logdevs.last.string.slice(beginning, config.log_size_limit).presence
+
+ config.parse_json ? JSON.parse(dump) : dump
+ rescue JSON::ParserError
+ dump
end
end