Sha256: b4fe6bdb8790ee5ba498d046b72ebaeafade5c7c1cec1d7ef5f66a1b94889854

Contents?: true

Size: 1.46 KB

Versions: 21

Compression:

Stored size: 1.46 KB

Contents

require "timber/context"

module Timber
  module Contexts
    # The HTTP context adds data about the current HTTP request being processed to your logs.
    # This allows you to tail and filter by this data. A very useful piece of data this
    # captures is the request ID. This gives you the ability to trace requests and view logs
    # for a specific request only. For example, say you've searched your logs and found the
    # specific line you are looking for, but it lacks context. With Timber you can simply
    # click the request ID and "zoom out" to view all logs for that request. This gives you
    # complete picture of how the log line in questio was generated.
    #
    # @note This context should be installed automatically through the,
    #   {Intregrations::Rack::HTTPContext} Rack middleware.
    class HTTP < Context
      @keyspace = :http

      attr_reader :method, :path, :remote_addr, :request_id

      def initialize(attributes)
        @method = attributes[:method] || raise(ArgumentError.new(":method is required"))
        @path = attributes[:path] || raise(ArgumentError.new(":path is required"))
        @remote_addr = attributes[:remote_addr]
        @request_id = attributes[:request_id]
      end

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def as_json(_options = {})
        {:method => method, :path => path, :remote_addr => remote_addr, :request_id => request_id}
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
timber-2.3.4 lib/timber/contexts/http.rb
timber-2.3.3 lib/timber/contexts/http.rb
timber-2.3.2 lib/timber/contexts/http.rb
timber-2.3.1 lib/timber/contexts/http.rb
timber-2.3.0 lib/timber/contexts/http.rb
timber-2.2.3 lib/timber/contexts/http.rb
timber-2.2.2 lib/timber/contexts/http.rb
timber-2.2.1 lib/timber/contexts/http.rb
timber-2.2.0 lib/timber/contexts/http.rb
timber-2.1.10 lib/timber/contexts/http.rb
timber-2.1.9 lib/timber/contexts/http.rb
timber-2.1.8 lib/timber/contexts/http.rb
timber-2.1.7 lib/timber/contexts/http.rb
timber-2.1.6 lib/timber/contexts/http.rb
timber-2.1.5 lib/timber/contexts/http.rb
timber-2.1.4 lib/timber/contexts/http.rb
timber-2.1.3 lib/timber/contexts/http.rb
timber-2.1.2 lib/timber/contexts/http.rb
timber-2.1.1 lib/timber/contexts/http.rb
timber-2.1.0 lib/timber/contexts/http.rb