Class: Bwrap::Output::Levels
- Inherits:
-
Object
- Object
- Bwrap::Output::Levels
- 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
- .debug? ⇒ Boolean
-
.debug_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
-
.error_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
-
.handle_output_options(options) ⇒ Object
Takes hash of options received from Optimist and checks output related flags.
-
.info_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
- .quiet? ⇒ Boolean
- .trace? ⇒ Boolean
-
.trace_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
- .verbose? ⇒ Boolean
-
.verbose_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
-
.warning_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
Methods included from Colors
Class Method Details
.debug? ⇒ Boolean
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.
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. if [:quiet] or [:silent] quiet! return end # Set output level flags to true or false, if it was given. unless [:trace].nil? @@_verbose = [:trace] @@_debug = [:trace] @@_trace = [:trace] end unless [:debug].nil? @@_verbose = [:debug] @@_debug = [:debug] end unless [:verbose].nil? @@_verbose = [:verbose] end end |
.info_print_formatted(str, log_callback: 1) ⇒ Object
Formats given string and outputs it.
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
30 31 32 |
# File 'lib/bwrap/output/levels.rb', line 30 def self.quiet? @@_quiet end |
.trace? ⇒ Boolean
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.
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
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.
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.
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 |