Class: TTY::Logger::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/logger/config.rb

Defined Under Namespace

Classes: FiltersProvider

Constant Summary collapse

FILTERED =
"[FILTERED]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a configuration instance



43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

#date_formatObject

The format used for date display. uses strftime format



11
12
13
# File 'lib/tty/logger/config.rb', line 11

def date_format
  @date_format
end

#filtersFiltersProvider

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

Returns:



79
80
81
# File 'lib/tty/logger/config.rb', line 79

def filters
  @filters ||= FiltersProvider.new
end

#formatterObject

The format used for displaying structured data



17
18
19
# File 'lib/tty/logger/config.rb', line 17

def formatter
  @formatter
end

#handlersObject

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



20
21
22
# File 'lib/tty/logger/config.rb', line 20

def handlers
  @handlers
end

#levelObject

The level to log messages at. Default to :info



23
24
25
# File 'lib/tty/logger/config.rb', line 23

def level
  @level
end

#max_bytesObject

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



26
27
28
# File 'lib/tty/logger/config.rb', line 26

def max_bytes
  @max_bytes
end

#max_depthObject

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



29
30
31
# File 'lib/tty/logger/config.rb', line 29

def max_depth
  @max_depth
end

#metadataObject

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



32
33
34
# File 'lib/tty/logger/config.rb', line 32

def 
  @metadata
end

#outputObject

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



35
36
37
# File 'lib/tty/logger/config.rb', line 35

def output
  @output
end

#time_formatObject

The format used for time display. uses strftime format



14
15
16
# File 'lib/tty/logger/config.rb', line 14

def time_format
  @time_format
end

#typesObject

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



38
39
40
# File 'lib/tty/logger/config.rb', line 38

def types
  @types
end

Instance Method Details

#to_hHash[Symbol]

Hash representation of this config

Returns:

  • (Hash[Symbol])


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# 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: ,
    output: output,
    time_format: time_format,
    types: types
  }
end

#to_procObject

Clone settings



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 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.dup
    config.output = @output.dup
    config.types = @types.dup
    config
  }
end