Class: GTA::FileLogger
- Inherits:
-
Object
- Object
- GTA::FileLogger
- Defined in:
- lib/gta/file_logger.rb
Instance Attribute Summary collapse
-
#log_dir ⇒ Object
readonly
Returns the value of attribute log_dir.
Instance Method Summary collapse
- #ensure_log_dir_and_file ⇒ Object
-
#initialize(log_dir = nil) ⇒ FileLogger
constructor
A new instance of FileLogger.
- #log_file ⇒ Object
- #write(stuff) ⇒ Object
Constructor Details
#initialize(log_dir = nil) ⇒ FileLogger
Returns a new instance of FileLogger.
5 6 7 8 |
# File 'lib/gta/file_logger.rb', line 5 def initialize(log_dir=nil) @log_dir = log_dir ||= "#{Dir.pwd}/log" ensure_log_dir_and_file end |
Instance Attribute Details
#log_dir ⇒ Object (readonly)
Returns the value of attribute log_dir.
3 4 5 |
# File 'lib/gta/file_logger.rb', line 3 def log_dir @log_dir end |
Instance Method Details
#ensure_log_dir_and_file ⇒ Object
10 11 12 13 |
# File 'lib/gta/file_logger.rb', line 10 def ensure_log_dir_and_file FileUtils.mkdir_p(log_dir) FileUtils.touch(log_file) unless File.exist?(log_file) end |
#log_file ⇒ Object
15 16 17 |
# File 'lib/gta/file_logger.rb', line 15 def log_file "#{log_dir}/gta.log" end |
#write(stuff) ⇒ Object
19 20 21 22 23 |
# File 'lib/gta/file_logger.rb', line 19 def write(stuff) File.open(log_file, 'a') do |f| f.write(stuff) end end |