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.



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_dirObject (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_fileObject



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_fileObject



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