Sha256: 8add47d31afe8884635b817e1bce9e2c837e9c1f8b5d8a17b054d51ccf55e6fb

Contents?: true

Size: 822 Bytes

Versions: 3

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

# Provides a hook in Rails controllers that allows enriching log lines from within a Rails request
# with data that is available only within a controller action, for instance user information.

module Loggery
  module Controller
    module LoggingContext
      extend ActiveSupport::Concern

      included do
        before_action :loggery_set_metadata
      end

      # to be overridden in including class
      def loggery_log_context
        {}
      end

      def loggery_set_metadata
        return unless Loggery::Metadata::Store.store

        metadata = loggery_default_metadata.merge loggery_log_context
        Loggery::Metadata::Store.store.merge!(metadata)
      end

      def loggery_default_metadata
        {}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loggery-0.3.0 lib/loggery/controller/logging_context.rb
loggery-0.2.1 lib/loggery/controller/logging_context.rb
loggery-0.2.0 lib/loggery/controller/logging_context.rb