Module: LoggerModule
- Included in:
- Logger, LoggerError
- Defined in:
- lib/logger.rb
Instance Method Summary collapse
- #initialize ⇒ Object
- #save(path) ⇒ Object
- #silence(&block) ⇒ Object
- #silent ⇒ Object
- #silent=(enable) ⇒ Object
- #strip_color(str) ⇒ Object
- #write_console(str, target) ⇒ Object
Instance Method Details
#initialize ⇒ Object
19 20 21 22 |
# File 'lib/logger.rb', line 19 def initialize super @is_silent = false end |
#save(path) ⇒ Object
48 49 50 |
# File 'lib/logger.rb', line 48 def save(path) File.write(path, string) end |
#silence(&block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/logger.rb', line 32 def silence(&block) raise "need a block" unless block tmp = self.silent self.silent = true block.call self.silent = tmp end |
#silent ⇒ Object
28 29 30 |
# File 'lib/logger.rb', line 28 def silent @is_silent end |
#silent=(enable) ⇒ Object
24 25 26 |
# File 'lib/logger.rb', line 24 def silent=(enable) @is_silent = !!enable end |
#strip_color(str) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/logger.rb', line 40 def strip_color(str) if $disable_color str else str.gsub(/(?:\e\[\d*[a-zA-Z])+/, "") end end |
#write_console(str, target) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/logger.rb', line 52 def write_console(str, target) unless @is_silent if $disable_color target.write(str) else write_color(str, target) end end end |