Class: Auth::Sanitizer::SanitizedLogger — Documentation by YARD 0.9.44

# Class: Auth::Sanitizer::SanitizedLogger

Inherits:
  Object
  - Object
  - Auth::Sanitizer::SanitizedLogger
  show all

Defined in:
  lib/auth/sanitizer/sanitized_logger.rb

## Overview

Logger wrapper that redacts sensitive values from debug output before
delegating to the underlying logger instance.

This class is intentionally narrow in scope: it only sanitizes string
messages emitted through the logging path and leaves request/response
behavior unchanged.

The underlying {ThingFilter} is initialized once when the logger wrapper is
created, so later config changes do not alter the behavior of existing
logger instances.

## Instance Method Summary collapse

- #<<(message) ⇒ Object

  Append a message to the underlying logger after sanitization.

- #add(severity, message = nil, progname = nil) ⇒ Object

  Add a log entry after sanitizing any string payloads.

- #close ⇒ void

  Close the underlying logger if supported.

- #debug(progname = nil, &block) ⇒ Object

  Log a debug message after sanitization.

- #error(progname = nil, &block) ⇒ Object

  Log an error message after sanitization.

- #fatal(progname = nil, &block) ⇒ Object

  Log a fatal message after sanitization.

- #formatter ⇒ Object?

  Access the formatter of the underlying logger if supported.

- #formatter=(formatter) ⇒ void

  Set the formatter of the underlying logger if supported.

- #info(progname = nil, &block) ⇒ Object

  Log an info message after sanitization.

- #initialize(logger, filtered_keys: Auth::Sanitizer.default_filtered_keys, label: Auth::Sanitizer.filtered_label) ⇒ SanitizedLogger constructor

  Create a new sanitized logger wrapper.

- #level ⇒ Object?

  Access the logger level if supported.

- #level=(level) ⇒ void

  Set the logger level if supported.

- #method_missing(method_name, *args) { ... } ⇒ Object

  Delegate unsupported methods to the wrapped logger.

- #progname ⇒ Object?

  Access the logger progname if supported.

- #progname=(progname) ⇒ void

  Set the logger progname if supported.

- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean

  Report support for methods provided by the wrapped logger.

- #unknown(progname = nil, &block) ⇒ Object

  Log an unknown-severity message after sanitization.

- #warn(progname = nil, &block) ⇒ Object

  Log a warning message after sanitization.

## Constructor Details

### #initialize(logger, filtered_keys: Auth::Sanitizer.default_filtered_keys, label: Auth::Sanitizer.filtered_label) ⇒ `SanitizedLogger`

Create a new sanitized logger wrapper.

Parameters:

- logger (`#add`, `#debug`, `#info`, `#warn`, `#error`, `#fatal`, `#unknown`) —

  The underlying logger instance that will receive sanitized messages.

- filtered_keys (`Array<String>`) (defaults to: `Auth::Sanitizer.default_filtered_keys`) —

  Key names whose values should be redacted in debug output.
  Defaults to Auth::Sanitizer.default_filtered_keys.

- label (`String`) (defaults to: `Auth::Sanitizer.filtered_label`) —

  Replacement label for redacted values.
  Defaults to Auth::Sanitizer.filtered_label.

    26
    27
    28
    29
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 26

    def initialize(logger, filtered_keys: Auth::Sanitizer.default_filtered_keys, label: Auth::Sanitizer.filtered_label)
      @logger = logger
      @thing_filter = ThingFilter.new(filtered_keys, label: label)
    end

## Dynamic Method Handling

This class handles dynamic methods through the `method_missing` method

### #method_missing(method_name, *args) { ... } ⇒ `Object`

Delegate unsupported methods to the wrapped logger.

Parameters:

- method_name (`Symbol`) —

  Method to invoke

- args (`Array<Object>`) —

  Method arguments

Yields:

- Deferred block forwarded to the wrapped logger

Returns:

- (`Object`) —

  The delegated result

    175
    176
    177
    178
    179
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 175

    def method_missing(method_name, *args, &block)
      return super unless @logger.respond_to?(method_name)

      @logger.public_send(method_name, *args, &block)
    end

## Instance Method Details

### #<<(message) ⇒ `Object`

Append a message to the underlying logger after sanitization.

Parameters:

- message (`String`) —

  Message to append

Returns:

- (`Object`) —

  The underlying logger result

    50
    51
    52
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 50

    def <<(message)
      @logger << sanitize(message)
    end

### #add(severity, message = nil, progname = nil) ⇒ `Object`

Add a log entry after sanitizing any string payloads.

Parameters:

- severity (`Integer`, `Symbol`, `String`, `nil`) —

  Logger severity

- message (`Object`, `nil`) (defaults to: `nil`) —

  Optional log message

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    38
    39
    40
    41
    42
    43
    44
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 38

    def add(severity, message = nil, progname = nil)
      if block_given?
        @logger.add(severity, sanitize(message), sanitize(progname)) { sanitize(yield) }
      else
        @logger.add(severity, sanitize(message), sanitize(progname))
      end
    end

### #close ⇒ `void`

This method returns an undefined value.

Close the underlying logger if supported.

    111
    112
    113
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 111

    def close
      @logger.close if @logger.respond_to?(:close)
    end

### #debug(progname = nil, &block) ⇒ `Object`

Log a debug message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    59
    60
    61
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 59

    def debug(progname = nil, &block)
      log(:debug, progname, &block)
    end

### #error(progname = nil, &block) ⇒ `Object`

Log an error message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    86
    87
    88
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 86

    def error(progname = nil, &block)
      log(:error, progname, &block)
    end

### #fatal(progname = nil, &block) ⇒ `Object`

Log a fatal message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    95
    96
    97
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 95

    def fatal(progname = nil, &block)
      log(:fatal, progname, &block)
    end

### #formatter ⇒ `Object`?

Access the formatter of the underlying logger if supported.

Returns:

- (`Object`, `nil`)

    118
    119
    120
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 118

    def formatter
      @logger.formatter if @logger.respond_to?(:formatter)
    end

### #formatter=(formatter) ⇒ `void`

This method returns an undefined value.

Set the formatter of the underlying logger if supported.

Parameters:

- formatter (`Object`) —

  Formatter object

    126
    127
    128
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 126

    def formatter=(formatter)
      @logger.formatter = formatter if @logger.respond_to?(:formatter=)
    end

### #info(progname = nil, &block) ⇒ `Object`

Log an info message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    68
    69
    70
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 68

    def info(progname = nil, &block)
      log(:info, progname, &block)
    end

### #level ⇒ `Object`?

Access the logger level if supported.

Returns:

- (`Object`, `nil`)

    133
    134
    135
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 133

    def level
      @logger.level if @logger.respond_to?(:level)
    end

### #level=(level) ⇒ `void`

This method returns an undefined value.

Set the logger level if supported.

Parameters:

- level (`Object`) —

  Logger level

    141
    142
    143
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 141

    def level=(level)
      @logger.level = level if @logger.respond_to?(:level=)
    end

### #progname ⇒ `Object`?

Access the logger progname if supported.

Returns:

- (`Object`, `nil`)

    148
    149
    150
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 148

    def progname
      @logger.progname if @logger.respond_to?(:progname)
    end

### #progname=(progname) ⇒ `void`

This method returns an undefined value.

Set the logger progname if supported.

Parameters:

- progname (`Object`) —

  Logger progname

    156
    157
    158
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 156

    def progname=(progname)
      @logger.progname = progname if @logger.respond_to?(:progname=)
    end

### #respond_to_missing?(method_name, include_private = false) ⇒ `Boolean`

Report support for methods provided by the wrapped logger.

Parameters:

- method_name (`Symbol`) —

  Method name to check

- include_private (`Boolean`) (defaults to: `false`) —

  Whether private methods are considered

Returns:

- (`Boolean`)

    165
    166
    167
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 165

    def respond_to_missing?(method_name, include_private = false)
      @logger.respond_to?(method_name, include_private) || super
    end

### #unknown(progname = nil, &block) ⇒ `Object`

Log an unknown-severity message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    104
    105
    106
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 104

    def unknown(progname = nil, &block)
      log(:unknown, progname, &block)
    end

### #warn(progname = nil, &block) ⇒ `Object`

Log a warning message after sanitization.

Parameters:

- progname (`Object`, `nil`) (defaults to: `nil`) —

  Optional program name

Yield Returns:

- (`Object`) —

  Deferred log message

Returns:

- (`Object`) —

  The underlying logger result

    77
    78
    79
    # File 'lib/auth/sanitizer/sanitized_logger.rb', line 77

    def warn(progname = nil, &block)
      log(:warn, progname, &block)
    end