Class: Julewire::SemanticLogger::Destination

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/semantic_logger/destination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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,
               **transport_options)
  @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(**transport_options)
  @health = Core::Integration::DestinationHealth.new(
    counter_keys: %i[received formatted written failed],
    failure_counter: :failed
  )
end

Instance Attribute Details

#nameObject (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! }

#closeObject



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

#flushObject



35
# File 'lib/julewire/semantic_logger/destination.rb', line 35

def flush(*) = call_lifecycle(:flush) { @transport.flush }

#healthObject



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

#reopenObject



39
# File 'lib/julewire/semantic_logger/destination.rb', line 39

def reopen(*) = call_lifecycle(:reopen) { @transport.reopen }

#resource_identityObject



43
# File 'lib/julewire/semantic_logger/destination.rb', line 43

def resource_identity = @transport