module Pundit::Logger::Configuration

Attributes

base_controller[W]

@param [String] ('ActionController::Base')

Name of the controller to add logging to.
log_controller_policy_summary[W]

Enable logging a summary of all policies and scopes used in a controller request, after the action completes.

Note that policies invoked by serializers are not logged at this time.

@param [Boolean] (true) logging enabled when truthy,

disabled when falsey
log_level[W]

@param [Symbol] (:debug) The method to call on the defined

logger, or the standard Rails logger methods
If using the Rails.logger, options include
  :debug, :warn: :info, :error
log_scope_instantiation[W]

Enable logging when a Scope is instantiated. This can help identify the source of SQL queries following in the logs.

@param [String, false, nil] (true) logging enabled when,

truthy, disabled when falsey
log_unauthorized_policies[W]

Enable logging when a policy returns unauthorized (a Pundit::NotAuthorizedError), and that error is unhandled, bubbling up to the controller).

This logging includes the policy and the arguments, to help debug why the action was unauthorized.

@param [Boolean] (true) logging enabled when truthy,

disabled when falsey
logger[W]

@param [#deug] (Rails.logger) The logger which the

gem will write to. Must respond to whatever the
configuration for #log_level is. (:debug by default)

If the logger responds to #tagged, tagged logging
will be utilized. You can disable tagged logging
with #logger_tag:
  config.logger_tag = false
logger_tag[W]

@param [String, false, nil] ('PUNDIT') The tag to use for

tagged_logging. This prefixes any output to your logs
from this gem.
If nil or false, tagged logging will not be used.

Public Instance Methods

base_controller() click to toggle source
# File lib/pundit_logger/configuration.rb, line 19
def base_controller
  (
    @base_controller || 'ActionController::Base'
  ).constantize
end
configure() { |self| ... } click to toggle source

Used to configure Pundit:Logger in your application.

@example

# config/initializers/pundit_logger.rb

Pundit::Logger.configure do |config|
  config.log_level = :warn
end
# File lib/pundit_logger/configuration.rb, line 12
def configure
  yield self if block_given?
end
log_controller_policy_summary?() click to toggle source
# File lib/pundit_logger/configuration.rb, line 101
def log_controller_policy_summary?
  if instance_variable_defined?(:@log_controller_policy_summary)
    @log_controller_policy_summary
  else
    true
  end
end
log_level() click to toggle source
# File lib/pundit_logger/configuration.rb, line 30
def log_level
  @log_level ||= :debug
end
log_scope_instantiation?() click to toggle source
# File lib/pundit_logger/configuration.rb, line 66
def log_scope_instantiation?
  if instance_variable_defined?(:@log_scope_instantiation)
    @log_scope_instantiation
  else
    true
  end
end
log_unauthorized_policies?() click to toggle source
# File lib/pundit_logger/configuration.rb, line 84
def log_unauthorized_policies?
  if instance_variable_defined?(:@log_unauthorized_policies)
    @log_unauthorized_policies
  else
    true
  end
end
logger() click to toggle source
# File lib/pundit_logger/configuration.rb, line 43
def logger
  @logger ||= Rails.logger
end
logger_tag() click to toggle source
# File lib/pundit_logger/configuration.rb, line 52
def logger_tag
  if instance_variable_defined?(:@logger_tag)
    @logger_tag
  else
    'PUNDIT'
  end
end