Class: TTY::Logger::Config
- Inherits:
-
Object
- Object
- TTY::Logger::Config
- Defined in:
- lib/tty/logger/config.rb
Defined Under Namespace
Classes: FiltersProvider
Constant Summary collapse
- FILTERED =
"[FILTERED]"
Instance Attribute Summary collapse
-
#date_format ⇒ Object
The format used for date display.
-
#filters ⇒ FiltersProvider
The filters to hide sensitive data from the message(s) and data.
-
#formatter ⇒ Object
The format used for displaying structured data.
-
#handlers ⇒ Object
The handlers used to display logging info.
-
#level ⇒ Object
The level to log messages at.
-
#max_bytes ⇒ Object
The maximum message size to be logged in bytes.
-
#max_depth ⇒ Object
The maximum depth for formatting array and hash objects.
-
#metadata ⇒ Object
The meta info to display, can be :date, :time, :file, :pid.
-
#output ⇒ Object
The output for the log messages.
-
#time_format ⇒ Object
The format used for time display.
-
#types ⇒ Object
The new custom log types.
Instance Method Summary collapse
-
#initialize(**options) ⇒ Config
constructor
private
Create a configuration instance.
-
#to_h ⇒ Hash[Symbol]
Hash representation of this config.
-
#to_proc ⇒ Object
Clone settings.
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(**) @max_bytes = .fetch(:max_bytes) { 2**13 } @max_depth = .fetch(:max_depth) { 3 } @level = .fetch(:level) { :info } @metadata = .fetch(:metadata) { [] } @handlers = .fetch(:handlers) { [:console] } @formatter = .fetch(:formatter) { :text } @date_format = .fetch(:date_format) { "%F" } @time_format = .fetch(:time_format) { "%T.%3N" } @output = .fetch(:output) { $stderr } @types = .fetch(:types) { {} } end |
Instance Attribute Details
#date_format ⇒ Object
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 |
#filters ⇒ FiltersProvider
The filters to hide sensitive data from the message(s) and data.
79 80 81 |
# File 'lib/tty/logger/config.rb', line 79 def filters @filters ||= FiltersProvider.new end |
#formatter ⇒ Object
The format used for displaying structured data
17 18 19 |
# File 'lib/tty/logger/config.rb', line 17 def formatter @formatter end |
#handlers ⇒ Object
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 |
#level ⇒ Object
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_bytes ⇒ Object
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_depth ⇒ Object
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 |
#metadata ⇒ Object
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 |
#output ⇒ Object
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_format ⇒ Object
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 |
#types ⇒ Object
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_h ⇒ Hash[Symbol]
Hash representation of this config
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_proc ⇒ Object
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 |