Class: Peastash::LogDevice

Inherits:
Logger::LogDevice
  • Object
show all
Defined in:
lib/peastash/log_device.rb

Instance Method Summary collapse

Instance Method Details

#open_logfile(filename) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/peastash/log_device.rb', line 6

def open_logfile(filename)
  super
rescue Errno::EACCES
  stat_data = File.stat(filename) rescue nil
  STDERR.puts "[#{Time.now}][#{Process.pid}] Could not open #{filename} for writing, recreating it. Info: #{stat_data.inspect}"
  FileUtils.rm(filename)
  create_logfile(filename)
rescue Errno::ENOENT => e
  require 'tempfile'
  temp_file = Tempfile.new([filename, '.log'])
  STDERR.puts "[#{Time.now}][#{Process.pid}] Could not open #{filename} for writing: #{e.message}. Data will be writen in: #{temp_file.path}"
  open_logfile(temp_file.path)
end