Class: Onlylogs::SocketLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/onlylogs/socket_logger.rb

Constant Summary collapse

DEFAULT_SOCKET =
"tmp/sockets/onlylogs-sidecar.sock"

Instance Method Summary collapse

Constructor Details

#initialize(local_fallback: $stdout, socket_path: ENV.fetch("ONLYLOGS_SIDECAR_SOCKET", DEFAULT_SOCKET)) ⇒ SocketLogger

Returns a new instance of SocketLogger.



13
14
15
16
17
18
# File 'lib/onlylogs/socket_logger.rb', line 13

def initialize(local_fallback: $stdout, socket_path: ENV.fetch("ONLYLOGS_SIDECAR_SOCKET", DEFAULT_SOCKET))
  super(local_fallback)
  @socket_path = socket_path
  @socket_mutex = Mutex.new
  @socket = nil
end

Instance Method Details

#add(severity, message = nil, progname = nil, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/onlylogs/socket_logger.rb', line 20

def add(severity, message = nil, progname = nil, &block)

  if message.nil?
    if block_given?
      message = block.call
    else
      message = progname
      progname = nil
    end
  end

  formatted = format_message(format_severity(severity), Time.now, progname, message.to_s)
  send_to_socket(formatted)
  super(severity, message, progname, &block)
end