Class: Ruote::TestLogger

Inherits:
Object
  • Object
show all
Includes:
PrettyLogging
Defined in:
lib/ruote/log/test_logger.rb

Direct Known Subclasses

WaitLogger

Constant Summary

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (TestLogger) initialize(context)

A new instance of TestLogger



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ruote/log/test_logger.rb', line 39

def initialize(context)

  @context = context

  if @context.worker
    #
    # this is a worker context, DO log
    #
    @context.worker.subscribe(:all, self)
  #else
    #
    # this is not a worker context, DO NOT log, but be ready to
    # be queried
    #
  end

  @seen = []
  @log = []
  @waiting = []

  @count = -1
  @color = 33
  @noisy = false
end

Instance Attribute Details

- (Object) log (readonly)

Returns the value of attribute log



35
36
37
# File 'lib/ruote/log/test_logger.rb', line 35

def log
  @log
end

- (Object) noisy

Returns the value of attribute noisy



37
38
39
# File 'lib/ruote/log/test_logger.rb', line 37

def noisy
  @noisy
end

- (Object) seen (readonly)

Returns the value of attribute seen



34
35
36
# File 'lib/ruote/log/test_logger.rb', line 34

def seen
  @seen
end

Class Method Details

+ (Object) pp(msg)



112
113
114
115
116
# File 'lib/ruote/log/test_logger.rb', line 112

def self.pp(msg)

  @logger ||= TestLogger.new(nil)
  puts @logger.send(:pretty_print, msg)
end

Instance Method Details

- (Object) color=(c)



107
108
109
110
# File 'lib/ruote/log/test_logger.rb', line 107

def color=(c)

  @color = c
end

- (Object) dump

Debug only : dumps all the seen events to STDOUTS



102
103
104
105
# File 'lib/ruote/log/test_logger.rb', line 102

def dump

  @seen.collect { |msg| pretty_print(msg) }.join("\n")
end

- (Object) notify(msg)



64
65
66
67
68
69
70
71
72
# File 'lib/ruote/log/test_logger.rb', line 64

def notify(msg)

  puts(pretty_print(msg)) if @noisy

  @seen << msg
  @log << msg

  check_waiting
end

- (Object) wait_for(interests)

Blocks until one or more interests are satisfied.

interests must be an array of interests. Please refer to Engine#wait_for documentation for allowed values of each interest.

If multiple interests are given, wait_for blocks until all of the interests are satisfied.

wait_for may only be used by one thread at a time. If one thread calls wait_for and later another thread calls wait_for while the first thread is waiting, the first thread's interests are lost and the first thread will never wake up.



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ruote/log/test_logger.rb', line 87

def wait_for(interests)

  @waiting << [ Thread.current, interests ]

  check_waiting

  Thread.stop if @waiting.find { |w| w.first == Thread.current }

  # and when this thread gets woken up, go on and return __result__

  Thread.current['__result__']
end