Class: GTA::FileLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/gta/file_logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_dir = nil) ⇒ FileLogger

Returns a new instance of FileLogger.



7
8
9
10
# File 'lib/gta/file_logger.rb', line 7

def initialize(log_dir=nil)
  @log_dir = log_dir ||= "#{Dir.pwd}/log"
  ensure_log_dir_and_file
end

Instance Attribute Details

#log_dirObject (readonly)

Returns the value of attribute log_dir.



5
6
7
# File 'lib/gta/file_logger.rb', line 5

def log_dir
  @log_dir
end

Instance Method Details

#ensure_log_dir_and_fileObject



12
13
14
15
# File 'lib/gta/file_logger.rb', line 12

def ensure_log_dir_and_file
  FileUtils.mkdir_p(log_dir)
  FileUtils.touch(log_file) unless File.exist?(log_file)
end

#log_fileObject



17
18
19
# File 'lib/gta/file_logger.rb', line 17

def log_file
  "#{log_dir}/gta.log"
end

#write(stuff) ⇒ Object



21
22
23
24
25
# File 'lib/gta/file_logger.rb', line 21

def write(stuff)
  File.open(log_file, 'a') do |f|
    f.write(stuff)
  end
end