Module: Ruote::D

Defined in:
lib/ruote/util/dlog.rb

Overview

Used for multi-worker debugging

Class Method Summary collapse

Class Method Details

.log(text, h, *args) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ruote/util/dlog.rb', line 33

def self.log(text, h, *args)

  @@log ||=
    begin
      f = File.open("dlog_#{$$}.txt", 'wb')
      f.sync = true
      f
    end

  t = Time.now
  t = "#{t.strftime('%H:%M:%S')}.#{sprintf('%06d', t.usec)}"

  m =
    [
      t,
      "p#{$$}",
      text,
      h['type'],
      h['_id'],
      h['_rev']
    ]

  if h['type'] == 'msgs'

    m << h['action']
    m << Ruote.extract_fei(h).short_sid rescue nil

    if h['action'] == 'reply'
      m << 'from'
      m << Ruote.extract_fei(h['workitem']).short_sid
    end
  end

  m.concat(args)
  m << "\n"

  @@log.print(m.collect(&:to_s).join(' '))
  @@log.flush # hard
end