Class: Debug
- Inherits:
-
Object
- Object
- Debug
- Defined in:
- lib/tiny_grabber/debug.rb
Overview
Save debug log information
Instance Attribute Summary collapse
-
#active ⇒ Object
Flag to active debug save log.
-
#destination ⇒ Object
Print log or save to file.
-
#save_html ⇒ Object
Flag to save response HTML to file.
Instance Method Summary collapse
-
#initialize ⇒ Debug
constructor
Initialize a debug object.
-
#save(message) ⇒ Object
Save log information.
-
#save_to_file(message) ⇒ Object
Save log information to file.
Constructor Details
#initialize ⇒ Debug
Initialize a debug object
12 13 14 15 16 |
# File 'lib/tiny_grabber/debug.rb', line 12 def initialize @active = false @destination = :print @save_html = false end |
Instance Attribute Details
#active ⇒ Object
Flag to active debug save log
4 5 6 |
# File 'lib/tiny_grabber/debug.rb', line 4 def active @active end |
#destination ⇒ Object
Print log or save to file
6 7 8 |
# File 'lib/tiny_grabber/debug.rb', line 6 def destination @destination end |
#save_html ⇒ Object
Flag to save response HTML to file
8 9 10 |
# File 'lib/tiny_grabber/debug.rb', line 8 def save_html @save_html end |
Instance Method Details
#save(message) ⇒ Object
Save log information
22 23 24 25 26 27 28 29 30 |
# File 'lib/tiny_grabber/debug.rb', line 22 def save() = "TG | #{Time.now.strftime('%Y%m%d-%H%M%S')} | #{}" case @destination when :file save_to_file when :print p end end |
#save_to_file(message) ⇒ Object
Save log information to file
36 37 38 39 40 41 42 43 |
# File 'lib/tiny_grabber/debug.rb', line 36 def save_to_file() # Encode message for correct Unix encoding = .force_encoding('utf-8') debug_path = "#{Dir.pwd}/log" Dir.mkdir(debug_path, 0o775) unless File.exist? debug_path filename = "#{Time.now.strftime('%Y%m%d')}.log" File.open("#{debug_path}/#{filename}", 'a+') { |f| f << "#{}\r\n" } end |