Class: Bwrap::Output::Levels

Inherits:
Object
  • Object
show all
Includes:
Colors
Defined in:
lib/bwrap/output/levels.rb

Overview

Output level functionality.

Constant Summary collapse

@@_verbose =
false
@@_debug =
false
@@_trace =
ENV.fetch("BWRAP_TRACE", nil) && true || false
@@_quiet =
false

Class Method Summary collapse

Methods included from Colors

color, stopcolor

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)

See Also:

  • Bwrap::Output##debug?


20
21
22
# File 'lib/bwrap/output/levels.rb', line 20

def self.debug?
  @@_debug
end

.debug_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.

Returns:

  • formatted string



70
71
72
73
74
75
76
# File 'lib/bwrap/output/levels.rb', line 70

def self.debug_print_formatted str, log_callback: 1
  out = "#{Bwrap::Output::Colors.color(190, 190, 190)}[DEBUG]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = append_caller out, log_callback: (log_callback + 1)
  puts out

  out
end

.error_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.



113
114
115
116
117
# File 'lib/bwrap/output/levels.rb', line 113

def self.error_print_formatted str, log_callback: 1
  out = "#{Bwrap::Output::Colors.color(230, 110, 110, bold: true)}[ERROR]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = "#{out} (called at #{caller_locations(log_callback, 1)[0]})" if @@_debug or @@_trace
  $stderr.puts out
end

.handle_output_options(options) ⇒ Object

Takes hash of options received from Optimist and checks output related flags.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bwrap/output/levels.rb', line 35

def self.handle_output_options options
  if options[:quiet] or options[:silent]
    quiet!
    return
  end

  # Set output level flags to true or false, if it was given.
  unless options[:trace].nil?
    @@_verbose = options[:trace]
    @@_debug = options[:trace]
    @@_trace = options[:trace]
  end
  unless options[:debug].nil?
    @@_verbose = options[:debug]
    @@_debug = options[:debug]
  end
  unless options[:verbose].nil?
    @@_verbose = options[:verbose]
  end
end

.info_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.

Returns:

  • formatted string



81
82
83
84
85
86
87
88
# File 'lib/bwrap/output/levels.rb', line 81

def self.info_print_formatted str, log_callback: 1
  # TODO: Maybe have different color for NOTICE than for INFO?
  out = "#{Bwrap::Output::Colors.color(130, 230, 130, bold: true)}[NOTICE]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = append_caller out, log_callback: (log_callback + 1)
  puts out

  out
end

.quiet?Boolean

Returns:

  • (Boolean)

See Also:

  • Bwrap::Output##quiet?


30
31
32
# File 'lib/bwrap/output/levels.rb', line 30

def self.quiet?
  @@_quiet
end

.trace?Boolean

Returns:

  • (Boolean)

See Also:

  • Bwrap::Output##trace?


25
26
27
# File 'lib/bwrap/output/levels.rb', line 25

def self.trace?
  @@_trace
end

.trace_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.

Returns:

  • formatted string



59
60
61
62
63
64
65
# File 'lib/bwrap/output/levels.rb', line 59

def self.trace_print_formatted str, log_callback: 1
  out = "#{Bwrap::Output::Colors.color(230, 165, 240)}[TRACE]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = append_caller out, log_callback: (log_callback + 1)
  puts out

  out
end

.verbose?Boolean

Returns:

  • (Boolean)

See Also:

  • Bwrap::Output#verbose?


15
16
17
# File 'lib/bwrap/output/levels.rb', line 15

def self.verbose?
  @@_verbose
end

.verbose_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.

Returns:

  • formatted string



93
94
95
96
97
98
99
# File 'lib/bwrap/output/levels.rb', line 93

def self.verbose_print_formatted str, log_callback: 1
  out = "#{Bwrap::Output::Colors.color(130, 230, 130, bold: true)}[INFO]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = append_caller out, log_callback: (log_callback + 1)
  puts out

  out
end

.warning_print_formatted(str, log_callback: 1) ⇒ Object

Formats given string and outputs it.

Returns:

  • formatted string



104
105
106
107
108
109
110
# File 'lib/bwrap/output/levels.rb', line 104

def self.warning_print_formatted str, log_callback: 1
  out = "#{Bwrap::Output::Colors.color(190, 190, 110, bold: true)}[WARN]#{Bwrap::Output::Colors.stopcolor} #{str}"
  out = "#{out} (called at #{caller_locations(log_callback, 1)[0]})" if @@_debug or @@_trace
  $stderr.puts out

  out
end