Module: Logging

Constant Summary collapse

QUIET =

Verbosity levels

0
NORMAL =
1
VERBOSE =
2
DEBUG =
3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.verbosity ⇒ Integer

Returns The current verbosity level.

Returns:

  • (Integer) —

    The current verbosity level.



17
18
19
# File 'lib/util/log.rb', line 17

def self.verbosity
  @verbosity
end

.verbosity=(level) ⇒ nil

Parameters:

  • level (Integer) —

    The new verbosity level.

Returns:

  • (nil)


23
24
25
26
27
28
# File 'lib/util/log.rb', line 23

def self.verbosity=(level)
  # warn "Logging.verbosity= called. Changing from #{@verbosity} to #{level}" \
  #   if (@verbosity || NORMAL) >= NORMAL ||
  #      (level || NORMAL) >= NORMAL
  @verbosity = level
end

Instance Method Details

#log(level, multiline_string, color = nil) ⇒ nil

A thread-safe output method for colored text to STDERR.

Parameters:

  • level (Integer) —

    The verbosity level of the message.

  • multiline_string (String) —

    The message to log.

  • color (Symbol, nil) (defaults to: nil) —

    The color method to apply from Rainbow, e.g., :red, :green. If nil, no color is applied.

Returns:

  • (nil)


35
36
37
38
39
40
41
42
43
44
# File 'lib/util/log.rb', line 35

def log(level, multiline_string, color = nil)
  return unless Logging.verbosity >= level

  multiline_string.to_s.each_line do |line|
    line_to_print = line.chomp
    line_to_print = line_to_print.public_send(color) if color
    warn line_to_print
  end
  $stderr.flush
end

#log_stdout(multiline_string) ⇒ nil

A thread-safe output method for uncolored text to STDOUT.

Parameters:

  • multiline_string (String) —

    The message to log.

Returns:

  • (nil)


49
50
51
52
# File 'lib/util/log.rb', line 49

def log_stdout(multiline_string)
  $stdout.puts multiline_string.to_s
  $stdout.flush
end