class TTY::Logger::Config

Constants

FILTERED

Attributes

date_format[RW]

The format used for date display. uses strftime format

filters[W]

Allow to overwirte filters

formatter[RW]

The format used for displaying structured data

handlers[RW]

The handlers used to display logging info. Defaults to [:console]

level[RW]

The level to log messages at. Default to :info

max_bytes[RW]

The maximum message size to be logged in bytes. Defaults to 8192

max_depth[RW]

The maximum depth for formatting array and hash objects. Defaults to 3

metadata[RW]

The meta info to display, can be :date, :time, :file, :pid. Defaults to []

output[RW]

The output for the log messages. Defaults to `stderr`

time_format[RW]

The format used for time display. uses strftime format

types[RW]

The new custom log types. Defaults to `{}`

Public Class Methods

new(**options) click to toggle source

Create a configuration instance

@api private

# File lib/tty/logger/config.rb, line 43
def initialize(**options)
  @max_bytes = options.fetch(:max_bytes) { 2**13 }
  @max_depth = options.fetch(:max_depth) { 3 }
  @level = options.fetch(:level) { :info }
  @metadata = options.fetch(:metadata) { [] }
  @handlers = options.fetch(:handlers) { [:console] }
  @formatter = options.fetch(:formatter) { :text }
  @date_format = options.fetch(:date_format) { "%F" }
  @time_format = options.fetch(:time_format) { "%T.%3N" }
  @output = options.fetch(:output) { $stderr }
  @types = options.fetch(:types) { {} }
end

Public Instance Methods

filters() click to toggle source

The filters to hide sensitive data from the message(s) and data.

@return [FiltersProvider]

@api public

# File lib/tty/logger/config.rb, line 79
def filters
  @filters ||= FiltersProvider.new
end
to_h() click to toggle source

Hash representation of this config

@return [Hash]

@api public

# File lib/tty/logger/config.rb, line 111
def to_h
  {
    date_format: date_format,
    filters: filters.to_h,
    formatter: formatter,
    handlers: handlers,
    level: level,
    max_bytes: max_bytes,
    max_depth: max_depth,
    metadata: metadata,
    output: output,
    time_format: time_format,
    types: types
  }
end
to_proc() click to toggle source

Clone settings

@api public

# File lib/tty/logger/config.rb, line 89
def to_proc
  -> (config) {
    config.date_format = @date_format.dup
    config.time_format = @time_format.dup
    config.filters = @filters.dup
    config.formatter = @formatter
    config.handlers = @handlers.dup
    config.level =  @level
    config.max_bytes = @max_bytes
    config.max_depth = @max_depth
    config.metadata = @metadata.dup
    config.output = @output.dup
    config.types = @types.dup
    config
  }
end