Module: CTioga::Log

Extended by:
Forwardable
Included in:
CTable, Debug, EdgesAndAxes, EdgesAndAxes::Axis, Label, Layout, LegendItem, LegendStyle, PlotMaker, PlotStyle, TiogaElement, TiogaPrimitiveMaker
Defined in:
lib/CTioga/log.rb

Overview

This module contains code to be included by PlotMaker for debugging. Even if it doesn’t deserve a real module of it’s own, it makes sense to have it separated anyway.

Instance Method Summary collapse

Instance Method Details

#identify(obj) ⇒ Object

Returns a string suitable for identification of an object, but without instance variables.



67
68
69
# File 'lib/CTioga/log.rb', line 67

def identify(obj)
  return "#<#{obj.class} 0x%x>" % obj.object_id
end

#init_logger(stream = STDERR) ⇒ Object



29
30
31
32
33
# File 'lib/CTioga/log.rb', line 29

def init_logger(stream = STDERR)
  Logger::Formatter::Format.replace("[%4$s] %6$s\n")
  @@log = Logger.new(stream)
  @@log.level = Logger::WARN # Warnings and more only by default
end

#loggerObject

Simple accessor for the @@log class variable.



36
37
38
# File 'lib/CTioga/log.rb', line 36

def logger
  return @@log
end

#logger_options(opt) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/CTioga/log.rb', line 40

def logger_options(opt)
  opt.on("-v", "--verbose", "Display useful information") do
    @@log.level = Logger::INFO
  end
  opt.on("--debug", "Turn on debugging info") do
    @@log.level = Logger::DEBUG
  end
  opt.on("--quiet", "Display only errors") do
    @@log.level = Logger::ERROR
  end
end

#spawn(cmd, priority = :info) ⇒ Object

A logging replacement for system



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/CTioga/log.rb', line 53

def spawn(cmd, priority = :info)
  retval = system(cmd)
  self.send(priority, "Running #{cmd} -> " + 
            if retval
              "success"
            else
              "failure"
            end
            )
  return retval
end