Module: Pundit::Logger::Configuration

Included in:
Pundit::Logger
Defined in:
lib/pundit_logger/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_controllerObject



19
20
21
22
23
# File 'lib/pundit_logger/configuration.rb', line 19

def base_controller
  (
    @base_controller || 'ActionController::Base'
  ).constantize
end

#log_controller_policy_summary=(value) ⇒ Object (writeonly)

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.

Parameters:

  • (true) (Boolean)

    logging enabled when truthy, disabled when falsey



100
101
102
# File 'lib/pundit_logger/configuration.rb', line 100

def log_controller_policy_summary=(value)
  @log_controller_policy_summary = value
end

#log_levelObject



30
31
32
# File 'lib/pundit_logger/configuration.rb', line 30

def log_level
  @log_level ||= :debug
end

#log_scope_instantiation=(value) ⇒ Object (writeonly)

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

Parameters:

  • (true) (String, false, nil)

    logging enabled when, truthy, disabled when falsey



65
66
67
# File 'lib/pundit_logger/configuration.rb', line 65

def log_scope_instantiation=(value)
  @log_scope_instantiation = value
end

#log_unauthorized_policies=(value) ⇒ Object (writeonly)

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.

Parameters:

  • (true) (Boolean)

    logging enabled when truthy, disabled when falsey



83
84
85
# File 'lib/pundit_logger/configuration.rb', line 83

def log_unauthorized_policies=(value)
  @log_unauthorized_policies = value
end

#loggerObject



43
44
45
# File 'lib/pundit_logger/configuration.rb', line 43

def logger
  @logger ||= Rails.logger
end

#logger_tagObject



52
53
54
55
56
57
58
# File 'lib/pundit_logger/configuration.rb', line 52

def logger_tag
  if instance_variable_defined?(:@logger_tag)
    @logger_tag
  else
    'PUNDIT'
  end
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Used to configure Pundit:Logger in your application.

Examples:

# config/initializers/pundit_logger.rb

Pundit::Logger.configure do |config|
  config.log_level = :warn
end

Yields:

  • (_self)

Yield Parameters:



12
13
14
# File 'lib/pundit_logger/configuration.rb', line 12

def configure
  yield self if block_given?
end

#log_controller_policy_summary?Boolean

Returns:

  • (Boolean)


101
102
103
104
105
106
107
# 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_scope_instantiation?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# 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?Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# 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