Class: Swee::SweeLogger
Instance Method Summary collapse
- #<<(msg) ⇒ Object
- #addlog(log) ⇒ Object
- #each_log ⇒ Object
- #get_binding ⇒ Object
- #get_file ⇒ Object
- #get_io ⇒ Object
- #init_fiber ⇒ Object
-
#initialize ⇒ SweeLogger
constructor
A new instance of SweeLogger.
- #logs ⇒ Object
- #loop_log ⇒ Object
- #roll! ⇒ Object
Constructor Details
#initialize ⇒ SweeLogger
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_log ⇒ Object
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_binding ⇒ Object
29 30 31 |
# File 'lib/swee/swee_logger.rb', line 29 def get_binding binding end |
#get_file ⇒ Object
48 49 50 |
# File 'lib/swee/swee_logger.rb', line 48 def get_file @logs.select { |log| log.file? }.first end |
#get_io ⇒ Object
44 45 46 |
# File 'lib/swee/swee_logger.rb', line 44 def get_io @logs.select { |log| log.io? }.first end |
#init_fiber ⇒ Object
11 12 13 |
# File 'lib/swee/swee_logger.rb', line 11 def init_fiber @fb = Fiber.new { loop_log } end |
#logs ⇒ Object
52 53 54 |
# File 'lib/swee/swee_logger.rb', line 52 def logs @logs end |
#loop_log ⇒ Object
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 |