Sha256: a30e385406083eca51b8b1cac27c5cf57b322925317ec39e3114b763934dc2b6
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
# frozen_string_literal: true require "logger" module Hanami class Logger < ::Logger # Filtering logic # # @since 1.1.0 # @api private class Filter # @since 1.1.0 # @api private def initialize(filters = []) @filters = filters end # @since 1.1.0 # @api private def call(hash) _filtered_keys(hash).each do |key| *keys, last = _actual_keys(hash, key.split(".")) keys.inject(hash, :fetch)[last] = "[FILTERED]" end hash end private # @since 1.1.0 # @api private attr_reader :filters # @since 1.1.0 # @api private def _filtered_keys(hash) _key_paths(hash).select { |key| filters.any? { |filter| key =~ %r{(\.|\A)#{filter}(\.|\z)} } } end # @since 1.1.0 # @api private def _key_paths(hash, base = nil) hash.inject([]) do |results, (k, v)| results + (_key_paths?(v) ? _key_paths(v, _build_path(base, k)) : [_build_path(base, k)]) end end # @since 1.1.0 # @api private def _build_path(base, key) [base, key.to_s].compact.join(".") end # @since 1.1.0 # @api private def _actual_keys(hash, keys) search_in = hash keys.inject([]) do |res, key| correct_key = search_in.key?(key.to_sym) ? key.to_sym : key search_in = search_in[correct_key] res + [correct_key] end end # Check if the given value can be iterated (`Enumerable`) and that isn't a `File`. # This is useful to detect closed `Tempfiles`. # # @since 1.3.5 # @api private # # @see https://github.com/hanami/utils/pull/342 def _key_paths?(value) value.is_a?(Enumerable) && !value.is_a?(File) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
hanami-utils-1.3.6 | lib/hanami/logger/filter.rb |
hanami-utils-1.3.5 | lib/hanami/logger/filter.rb |