Class: ExcADG::Log::RLogger

Inherits:
Ractor
  • Object
show all
Defined in:
lib/excadg/log.rb

Overview

ractor-based logger, this ractor logger receives messages from other ractors and log them,

Class Method Summary collapse

Class Method Details

.new(dest: $stdout, level: Logger::INFO) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/excadg/log.rb', line 15

def self.new dest: $stdout, level: Logger::INFO
  super(dest, level) { |dest, level|
    File.open(dest, 'w+', &:write) unless dest.is_a? IO
    l ||= Logger.new dest
    l.level = level
    l.formatter = proc { |severity, datetime, progname, msg|
      format('%20s | %4s | %-10s || %s', datetime, severity, progname, msg)
    }
    while log = Ractor.receive
      # Expect 3 args - severity, proc name and message
      l.public_send(log.first, log[1], &-> { log.last.to_s + "\n" })
    end
  }
end