Module: Dry::Logger::Global
- Included in:
- Dry::Logger
- Defined in:
- lib/dry/logger/global.rb
Overview
Global setup methods
Instance Method Summary collapse
-
#formatters ⇒ Object
private
Internal formatters registry.
-
#new(stream: $stdout, **options) ⇒ Backends::Stream
private
Build a logging backend instance.
-
#register_formatter(name, formatter) ⇒ Hash
Register a new formatter.
-
#register_template(name, template) ⇒ Hash
Register a new template.
-
#templates ⇒ Object
private
Internal templates registry.
Instance Method Details
#formatters ⇒ Object
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.
Internal formatters registry
110 111 112 |
# File 'lib/dry/logger/global.rb', line 110 def formatters @formatters ||= {} end |
#new(stream: $stdout, **options) ⇒ Backends::Stream
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.
Build a logging backend instance
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/dry/logger/global.rb', line 67 def new(stream: $stdout, **) backend = case stream when IO, StringIO then Backends::IO when String, Pathname then Backends::File else raise ArgumentError, "unsupported stream type #{stream.class}" end formatter_spec = [:formatter] template_spec = [:template] template = case template_spec when Symbol then templates.fetch(template_spec) when String then template_spec when nil then templates[:default] else raise ArgumentError, ":template option must be a Symbol or a String (`#{template_spec}` given)" end = {**, template: template} formatter = case formatter_spec when Symbol then formatters.fetch(formatter_spec).new(**) when Class then formatter_spec.new(**) when nil then formatters[:string].new(**) when ::Logger::Formatter then formatter_spec else raise ArgumentError, "Unsupported formatter option #{formatter_spec.inspect}" end = .select { |key, _| BACKEND_OPT_KEYS.include?(key) } backend.new(stream: stream, **, formatter: formatter) end |
#register_formatter(name, formatter) ⇒ Hash
Register a new formatter
34 35 36 37 |
# File 'lib/dry/logger/global.rb', line 34 def register_formatter(name, formatter) formatters[name] = formatter formatters end |
#register_template(name, template) ⇒ Hash
Register a new template
57 58 59 60 |
# File 'lib/dry/logger/global.rb', line 57 def register_template(name, template) templates[name] = template templates end |
#templates ⇒ Object
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.
Internal templates registry
118 119 120 |
# File 'lib/dry/logger/global.rb', line 118 def templates @templates ||= {} end |