class Swee::SweeLogger

Public Class Methods

new() click to toggle source
# File lib/swee/swee_logger.rb, line 4
def initialize
  @logs = Array.new
  @msg = Array.new
  init_fiber
end

Public Instance Methods

<<(msg) click to toggle source
# File lib/swee/swee_logger.rb, line 55
def <<(msg)
  @msg << msg
  roll!
end
addlog(log) click to toggle source
# File lib/swee/swee_logger.rb, line 39
def addlog log
  @logs << log
end
each_log() click to toggle source
# File lib/swee/swee_logger.rb, line 21
def each_log
  while !@msg.empty?
    _msg = @msg.shift
    @logs.each { |_log| _log.debug _msg }
  end
end
get_binding() click to toggle source
# File lib/swee/swee_logger.rb, line 28
def get_binding
  binding
end
get_file() click to toggle source
# File lib/swee/swee_logger.rb, line 47
def get_file
  @logs.select { |log| log.file? }.first
end
get_io() click to toggle source
# File lib/swee/swee_logger.rb, line 43
def get_io
  @logs.select { |log| log.io? }.first
end
init_fiber() click to toggle source
# File lib/swee/swee_logger.rb, line 10
def init_fiber
  @fb = Fiber.new { loop_log }
end
logs() click to toggle source
# File lib/swee/swee_logger.rb, line 51
def logs
  @logs
end
loop_log() click to toggle source
# File lib/swee/swee_logger.rb, line 14
def loop_log
  loop do
    each_log
    Fiber.yield
  end
end
roll!() click to toggle source
# File lib/swee/swee_logger.rb, line 32
def roll!
  each_log
  # Fiber 存在跨线程问题 暂时不用Fiber处理
  # init_fiber if !@fb.alive?
  # @fb.resume
end