Class: Julewire::SemanticLogger::Destination
- Inherits:
-
Object
- Object
- Julewire::SemanticLogger::Destination
- Defined in:
- lib/julewire/semantic_logger/destination.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #after_fork! ⇒ Object
- #close ⇒ Object
- #emit(record) ⇒ Object
- #flush ⇒ Object
- #health ⇒ Object
-
#initialize(name:, formatter:, encoder: ENCODER, transport: nil, on_drop: nil, on_failure: nil, **transport_options) ⇒ Destination
constructor
A new instance of Destination.
- #reopen ⇒ Object
- #resource_identity ⇒ Object
Constructor Details
#initialize(name:, formatter:, encoder: ENCODER, transport: nil, on_drop: nil, on_failure: nil, **transport_options) ⇒ Destination
Returns a new instance of Destination.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/julewire/semantic_logger/destination.rb', line 8 def initialize(name:, formatter:, encoder: ENCODER, transport: nil, on_drop: nil, on_failure: nil, **) @name = Core::Destinations.normalize_name(name) @formatter = formatter @encoder = encoder @on_drop = validate_optional_callback(on_drop, name: :on_drop) @on_failure = validate_optional_callback(on_failure, name: :on_failure) @transport = transport || Transport.new(**) @health = Core::Integration::DestinationHealth.new( counter_keys: %i[received formatted written failed], failure_counter: :failed ) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/julewire/semantic_logger/destination.rb', line 6 def name @name end |
Instance Method Details
#after_fork! ⇒ Object
41 |
# File 'lib/julewire/semantic_logger/destination.rb', line 41 def after_fork! = call_lifecycle(:after_fork) { @transport.after_fork! } |
#close ⇒ Object
37 |
# File 'lib/julewire/semantic_logger/destination.rb', line 37 def close(*) = call_lifecycle(:close) { @transport.close } |
#emit(record) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/julewire/semantic_logger/destination.rb', line 22 def emit(record) formatted = false increment(:received) payload = @formatter.call(record) formatted = true @transport.write(encoded_payload(payload), severity: record.fetch(:severity)) record_written nil rescue StandardError => e record_failure(e, formatted: formatted, record: record) nil end |
#flush ⇒ Object
35 |
# File 'lib/julewire/semantic_logger/destination.rb', line 35 def flush(*) = call_lifecycle(:flush) { @transport.flush } |
#health ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/julewire/semantic_logger/destination.rb', line 45 def health transport = @transport.health @health.snapshot( status: status(@health.degraded?, transport), type: "semantic_logger_destination", transport: transport ) end |
#reopen ⇒ Object
39 |
# File 'lib/julewire/semantic_logger/destination.rb', line 39 def reopen(*) = call_lifecycle(:reopen) { @transport.reopen } |
#resource_identity ⇒ Object
43 |
# File 'lib/julewire/semantic_logger/destination.rb', line 43 def resource_identity = @transport |