Class: Kino::Logger::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/kino/logger.rb

Overview

The raw IO-like device for integrations that want bytes without ::Logger's formatting: Rack::CommonLogger, ActiveSupport::Logger.new, a BroadcastLogger arm, ... Frozen and holding only an Integer id, so it is Ractor-shareable; one device can serve every worker.

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Device

Returns a new instance of Device.

Parameters:

  • path (String, nil) (defaults to: nil)

    a file (created/appended) or nil for stdout



32
33
34
35
# File 'lib/kino/logger.rb', line 32

def initialize(path = nil)
  @id = Native.log_device_open(path&.to_s)
  freeze
end

Instance Method Details

#closevoid

This method returns an undefined value.

Close the device: the flusher drains its queue and exits. Writes after close are ignored.



47
48
49
# File 'lib/kino/logger.rb', line 47

def close
  Native.log_device_close(@id)
end

#reopenObject

::Logger probes these on its device.



52
# File 'lib/kino/logger.rb', line 52

def reopen(*) = self

#write(message) ⇒ void Also known as: <<

This method returns an undefined value.

Queue one formatted line on the async sink; never blocks.

Parameters:

  • message (String)


40
41
42
# File 'lib/kino/logger.rb', line 40

def write(message)
  Native.log_device_write(@id, message.to_s)
end