Sha256: 76eec4fb17e0962d6f333b1847ab6697f2fe77c5686b9997c2dc689ab1ab740c

Contents?: true

Size: 988 Bytes

Versions: 5

Compression:

Stored size: 988 Bytes

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

      def initialize(attributes)
        @id = attributes[:id]
        @name = attributes[:name]
        @email = attributes[:email]
      end

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def as_json(_options = {})
        {id: Timber::Util::Object.try(id, :to_s), name: name, email: email}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
timber-2.1.3 lib/timber/contexts/user.rb
timber-2.1.2 lib/timber/contexts/user.rb
timber-2.1.1 lib/timber/contexts/user.rb
timber-2.1.0 lib/timber/contexts/user.rb
timber-2.1.0.rc6 lib/timber/contexts/user.rb