Class: Swee::SweeLogger

Inherits:
Object show all
Defined in:
lib/swee/swee_logger.rb

Instance Method Summary collapse

Constructor Details

#initializeSweeLogger

Returns a new instance of SweeLogger.



5
6
7
8
9
# File 'lib/swee/swee_logger.rb', line 5

def initialize
  @logs = Array.new
  @msg = Array.new
  init_fiber
end

Instance Method Details

#<<(msg) ⇒ Object



56
57
58
59
# File 'lib/swee/swee_logger.rb', line 56

def <<(msg)
  @msg << msg
  roll!
end

#addlog(log) ⇒ Object



40
41
42
# File 'lib/swee/swee_logger.rb', line 40

def addlog log
  @logs << log
end

#each_logObject



22
23
24
25
26
27
# File 'lib/swee/swee_logger.rb', line 22

def each_log
  while !@msg.empty?
    _msg = @msg.shift
    @logs.each { |_log| _log.debug _msg }
  end
end

#get_bindingObject



29
30
31
# File 'lib/swee/swee_logger.rb', line 29

def get_binding
  binding
end

#get_fileObject



48
49
50
# File 'lib/swee/swee_logger.rb', line 48

def get_file
  @logs.select { |log| log.file? }.first
end

#get_ioObject



44
45
46
# File 'lib/swee/swee_logger.rb', line 44

def get_io
  @logs.select { |log| log.io? }.first
end

#init_fiberObject



11
12
13
# File 'lib/swee/swee_logger.rb', line 11

def init_fiber
  @fb = Fiber.new { loop_log }
end

#logsObject



52
53
54
# File 'lib/swee/swee_logger.rb', line 52

def logs
  @logs
end

#loop_logObject



15
16
17
18
19
20
# File 'lib/swee/swee_logger.rb', line 15

def loop_log
  loop do
    each_log
    Fiber.yield
  end
end

#roll!Object



33
34
35
36
37
38
# File 'lib/swee/swee_logger.rb', line 33

def roll!
  each_log
  # Fiber 存在跨线程问题 暂时不用Fiber处理
  # init_fiber if [email protected]?
  # @fb.resume
end