Class: UU::LoggerFluent::Formatter
- Inherits:
-
Object
- Object
- UU::LoggerFluent::Formatter
- Defined in:
- lib/uu/logger_fluent.rb
Constant Summary collapse
- PATHS =
%w[ /log.rb /logger.rb /loggable.rb /forwardable.rb ].freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #call(severity, msg) ⇒ Object
- #find_location ⇒ Object
-
#initialize(context, tag) ⇒ Formatter
constructor
A new instance of Formatter.
- #metadata ⇒ Object
Constructor Details
#initialize(context, tag) ⇒ Formatter
Returns a new instance of Formatter.
8 9 10 11 |
# File 'lib/uu/logger_fluent.rb', line 8 def initialize(context, tag) @context = context @tag = tag end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
13 14 15 |
# File 'lib/uu/logger_fluent.rb', line 13 def context @context end |
Instance Method Details
#call(severity, msg) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/uu/logger_fluent.rb', line 15 def call(severity, msg) [@tag, { log_level: severity, **, message: msg, **@context.context, }] end |
#find_location ⇒ Object
40 41 42 43 44 45 |
# File 'lib/uu/logger_fluent.rb', line 40 def find_location caller_locations.find do |location_| location_.path != __FILE__ && PATHS.none? { |path| location_.path.end_with?(path) } end end |
#metadata ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/uu/logger_fluent.rb', line 24 def location = find_location { filename: File.basename(location.path), method: location.label, lineno: location.lineno, } end |