Module: Goat::Log

Included in:
Goat
Defined in:
lib/goat/net-common.rb

Class Method Summary collapse

Class Method Details

.lockpathObject



20
# File 'lib/goat/net-common.rb', line 20

def self.lockpath; "/tmp/#{logname}.lock"; end

.log(lvl, msg, termmsg = nil) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/goat/net-common.rb', line 23

def self.log(lvl, msg, termmsg=nil)
  logf.puts("#{tai64n} #{msg}")
  logf.flush

  termmsg ||= msg
  $stderr.puts("#{tai64n} #{termmsg}")
end

.log_message(msg) ⇒ Object



31
32
33
# File 'lib/goat/net-common.rb', line 31

def self.log_message(msg)
  log("#{msg['type']} #{msg.inspect}", "#{Term::ANSIColor.green(msg['type'])}: #{msg.inspect}")
end

.logfObject



21
# File 'lib/goat/net-common.rb', line 21

def self.logf; @log ||= File.open(logpath, 'a'); end

.lognameObject



18
# File 'lib/goat/net-common.rb', line 18

def self.logname; File.basename($0); end

.logpathObject



19
# File 'lib/goat/net-common.rb', line 19

def self.logpath; "/tmp/#{logname}.log"; end

.tai64nObject



9
10
11
12
13
14
15
16
# File 'lib/goat/net-common.rb', line 9

def self.tai64n
  # http://cr.yp.to/libtai/tai64.html
  # as of feb 9 2011, TAI - UTC = 34
  # see http://en.wikipedia.org/wiki/Leap_second
  tai_utc_diff = 34
  t = Time.now.utc
  "@40000000%08x%08x" % [t.to_i + tai_utc_diff, (t.to_f - t.to_i) * 10**9]
end