Sha256: 3ed0deb835d77d71acf0d020bbc9b15e0f44ca8aa0d04ce57ff91146e912ce1c

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

require "timber/context"
require "timber/util"

module Timber
  module Contexts
    # The user context adds data about the currently authenticated user to your logs.
    # By adding this context all of your logs will contain user information. This allows
    # filter and tail logs by specific users.
    #
    # @note This is tracked automatically with the {Integrations::Rack::UserContext} rack
    #   middleware for supported authentication frameworks. See {Integrations::Rack::UserContext}
    #   for more details.
    class User < Context
      @keyspace = :user

      attr_reader :id, :name, :email, :type, :meta

      def initialize(attributes)
        @id = Timber::Util::Object.try(attributes[:id], :to_s)
        @name = attributes[:name]
        @email = attributes[:email]
        @type = attributes[:type]
        @meta = attributes[:meta]
      end

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def as_json(_options = {})
        {id: id, name: name, email: email, type: type, meta: meta}
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timber-2.5.1 lib/timber/contexts/user.rb
timber-2.5.0 lib/timber/contexts/user.rb
timber-2.4.0 lib/timber/contexts/user.rb
timber-2.3.4 lib/timber/contexts/user.rb
timber-2.3.3 lib/timber/contexts/user.rb
timber-2.3.2 lib/timber/contexts/user.rb
timber-2.3.1 lib/timber/contexts/user.rb
timber-2.3.0 lib/timber/contexts/user.rb
timber-2.2.3 lib/timber/contexts/user.rb
timber-2.2.2 lib/timber/contexts/user.rb
timber-2.2.1 lib/timber/contexts/user.rb
timber-2.2.0 lib/timber/contexts/user.rb
timber-2.1.10 lib/timber/contexts/user.rb