Class: Onlylogs::SocketDevice
- Inherits:
-
Object
- Object
- Onlylogs::SocketDevice
- Defined in:
- lib/onlylogs/socket_device.rb
Overview
Send failures are reported to $stderr — never through a logger — so a failing socket can never re-enter logging and deadlock or loop.
Constant Summary collapse
- DEFAULT_SOCKET =
"tmp/sockets/onlylogs-sidecar.sock"
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(socket_path: ENV.fetch("ONLYLOGS_SIDECAR_SOCKET", DEFAULT_SOCKET)) ⇒ SocketDevice
constructor
A new instance of SocketDevice.
- #write(message) ⇒ Object
Constructor Details
#initialize(socket_path: ENV.fetch("ONLYLOGS_SIDECAR_SOCKET", DEFAULT_SOCKET)) ⇒ SocketDevice
Returns a new instance of SocketDevice.
11 12 13 14 15 |
# File 'lib/onlylogs/socket_device.rb', line 11 def initialize(socket_path: ENV.fetch("ONLYLOGS_SIDECAR_SOCKET", DEFAULT_SOCKET)) @socket_path = socket_path @socket_mutex = Mutex.new @socket = nil end |
Instance Method Details
#close ⇒ Object
30 31 32 |
# File 'lib/onlylogs/socket_device.rb', line 30 def close reconnect_socket end |
#write(message) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/onlylogs/socket_device.rb', line 17 def write() return if .nil? || .empty? socket = ensure_socket socket&.puts() rescue Errno::EPIPE, Errno::ECONNREFUSED, Errno::ENOENT => e $stderr.puts "Onlylogs::SocketDevice error: #{e.}" # rubocop:disable Style/StderrPuts reconnect_socket rescue => e $stderr.puts "Onlylogs::SocketDevice unexpected error: #{e.class}: #{e.}" # rubocop:disable Style/StderrPuts reconnect_socket end |