Sha256: 823872f2a9d46efd04831370393c5eb1c5b14f80048a11448e89784a62f8f0bc

Contents?: true

Size: 1.07 KB

Versions: 6

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 = attributes[:id]
        @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: Timber::Util::Object.try(id, :to_s), name: name, email: email, type: type, meta: meta}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
timber-2.1.9 lib/timber/contexts/user.rb
timber-2.1.8 lib/timber/contexts/user.rb
timber-2.1.7 lib/timber/contexts/user.rb
timber-2.1.6 lib/timber/contexts/user.rb
timber-2.1.5 lib/timber/contexts/user.rb
timber-2.1.4 lib/timber/contexts/user.rb