Module: PXCBackup::Logger
- Defined in:
- lib/pxcbackup/logger.rb
Class Method Summary collapse
- .action(message) ⇒ Object
- .action_end(message) ⇒ Object
- .action_start(message) ⇒ Object
- .blue(text) ⇒ Object
- .color_output=(value) ⇒ Object
- .colorize(text, color_code) ⇒ Object
- .debug(message) ⇒ Object
- .decrease_indentation ⇒ Object
- .green(text) ⇒ Object
- .increase_indentation ⇒ Object
- .info(message) ⇒ Object
- .output(message, skip_newline = false) ⇒ Object
- .raise_verbosity ⇒ Object
- .red(text) ⇒ Object
- .warning(message) ⇒ Object
- .yellow(text) ⇒ Object
Class Method Details
.action(message) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/pxcbackup/logger.rb', line 64 def self.action() return yield unless @verbosity_level >= 1 action_start() t1 = Time.now begin result = yield rescue => e action_end(red('fail')) raise e end t2 = Time.now action_end(green('done') + ' (%.1fs)' % (t2 - t1)) result end |
.action_end(message) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pxcbackup/logger.rb', line 41 def self.action_end() return unless @verbosity_level >= 1 if @partial puts @partial = false else output decrease_indentation end end |
.action_start(message) ⇒ Object
35 36 37 38 39 |
# File 'lib/pxcbackup/logger.rb', line 35 def self.action_start() return unless @verbosity_level >= 1 output "#{message}: ", true @partial = true end |
.blue(text) ⇒ Object
96 97 98 |
# File 'lib/pxcbackup/logger.rb', line 96 def self.blue(text) colorize(text, 34); end |
.color_output=(value) ⇒ Object
20 21 22 |
# File 'lib/pxcbackup/logger.rb', line 20 def self.color_output=(value) @color_output = value end |
.colorize(text, color_code) ⇒ Object
80 81 82 |
# File 'lib/pxcbackup/logger.rb', line 80 def self.colorize(text, color_code) @color_output ? "\e[#{color_code}m#{text}\e[0m" : text end |
.debug(message) ⇒ Object
60 61 62 |
# File 'lib/pxcbackup/logger.rb', line 60 def self.debug() output blue() if @verbosity_level >= 2 end |
.decrease_indentation ⇒ Object
16 17 18 |
# File 'lib/pxcbackup/logger.rb', line 16 def self.decrease_indentation @indentation -= 1 end |
.green(text) ⇒ Object
88 89 90 |
# File 'lib/pxcbackup/logger.rb', line 88 def self.green(text) colorize(text, 32) end |
.increase_indentation ⇒ Object
12 13 14 |
# File 'lib/pxcbackup/logger.rb', line 12 def self.increase_indentation @indentation += 1 end |
.info(message) ⇒ Object
52 53 54 |
# File 'lib/pxcbackup/logger.rb', line 52 def self.info() output if @verbosity_level >= 1 end |
.output(message, skip_newline = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pxcbackup/logger.rb', line 24 def self.output(, skip_newline = false) if @partial puts increase_indentation @partial = false end print ' ' * @indentation + puts unless skip_newline $stdout.flush end |
.raise_verbosity ⇒ Object
8 9 10 |
# File 'lib/pxcbackup/logger.rb', line 8 def self.raise_verbosity @verbosity_level += 1 end |
.red(text) ⇒ Object
84 85 86 |
# File 'lib/pxcbackup/logger.rb', line 84 def self.red(text) colorize(text, 31); end |
.warning(message) ⇒ Object
56 57 58 |
# File 'lib/pxcbackup/logger.rb', line 56 def self.warning() output yellow() if @verbosity_level >= 1 end |
.yellow(text) ⇒ Object
92 93 94 |
# File 'lib/pxcbackup/logger.rb', line 92 def self.yellow(text) colorize(text, 33); end |