1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-02-01 01:37:12 +00:00

Remove scope parameter from Logger#tag and Buffer#tag

This reduces the change of a Hash argument being interpreted as keyword
argument inadvertently and clarifies the interface. If a resolver scope
is required, you can also call

    delayed_tag = ->{ |request| request.host }
    logger.tags.merge!(delayed_tag, scope: request)
This commit is contained in:
Holger Just 2019-10-07 19:58:16 +02:00
parent b3466779bb
commit 7fe284309b
4 changed files with 8 additions and 12 deletions

View File

@ -263,15 +263,11 @@ module Rackstash
# @param new_tags [Array<#to_s, #call>] Strings to add as tags to the buffer.
# You can either give (arrays of) strings here or procs which return
# a string or an array of strings when called.
# @param scope [nil, Object] If anything other then `nil` is given here, we
# will evaluate any procs given in the tags in the context of this
# object. If `nil` is given (the default) the procs are directly called
# in the context where they were created.
# @return [Fields::Tags] the resolved tags which are set on the buffer.
# All strings are frozen.
def tag(*new_tags, scope: nil)
def tag(*new_tags)
timestamp
tags.merge!(new_tags, scope: scope)
tags.merge!(new_tags)
end
# @return [Fields::Tags] a tags list containing the defined tags for the

View File

@ -187,8 +187,8 @@ module Rackstash
end
# (see Buffer#tag)
def tag(*new_tags, scope: nil)
buffer.tag(*new_tags, scope: scope)
def tag(*new_tags)
buffer.tag(*new_tags)
end
# (see Buffer#tags)

View File

@ -246,7 +246,7 @@ module Rackstash
scope: request,
force: false
) unless @request_fields.nil?
@logger.tag(@request_tags, scope: request) unless @request_tags.nil?
@logger.tags.merge!(@request_tags, scope: request) unless @request_tags.nil?
end
# @param env [Hash] the Rack environment
@ -285,7 +285,7 @@ module Rackstash
force: false
) unless @response_fields.nil?
@logger.tag(@response_tags, scope: headers) unless @response_tags.nil?
@logger.tags.merge!(@response_tags, scope: headers) unless @response_tags.nil?
end
# @param env [Hash] The Rack environment

View File

@ -486,12 +486,12 @@ RSpec.describe Rackstash::Buffer do
}
it 'expands single-value proc objects' do
buffer.tag(-> { self }, scope: object)
buffer.tag(-> { object })
expect(buffer.tags).to contain_exactly('Hello')
end
it 'expands multi-value proc objects' do
buffer.tag(-> { [[self, 'foobar'], 123] }, scope: object)
buffer.tag(-> { [[object, 'foobar'], 123] })
expect(buffer.tags).to contain_exactly('Hello', 'foobar', '123')
end
end