def capture(buffer_args = {})
      raise ArgumentError, 'block required' unless block_given?

      buffer_stack.push(buffer_args)
      begin
        yield
      ensure
        buffer_stack.flush_and_pop
      end
    end
def capture(buffer_args = {})
      raise ArgumentError, 'block required' unless block_given?

      buffer_stack.push(buffer_args)
      begin
        yield
      ensure
        buffer_stack.flush_and_pop
      end
    end
Capture all messages and fields logged for the duration of the provided
 block in the current thread.

 Create a new {Buffer} and put in on the {BufferStack} for the current
 thread. For the duration of the block, all new logged messages and any
 access to fields and tags will be sent to this new buffer. Previous
 buffers created in the same thread will only be visible after the
 execution left the block.

 Note that the created {Buffer} is only valid for the current thread. In
 other threads, it not visible and will thus not be used.

 @param buffer_args [Hash<Symbol => Object>] optional arguments for the new
   {Buffer}. See {Buffer#initialize} for allowed values.
 @yield During the duration of the block, all logged messages, fields and
   tags are set on the new buffer. After the block returns, the {Buffer} is
   removed from the {BufferStack} again and is always flushed
   automatically.
 @return [Object] the return value of the block