Class: BatchManager::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_manager/logger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(batch_name, is_wet, disable_stdout = false) ⇒ Logger

Returns a new instance of Logger.



16
17
18
19
20
21
22
23
24
# File 'lib/batch_manager/logger.rb', line 16

def initialize(batch_name, is_wet, disable_stdout = false)
  @logger = Log4r::Logger.new(batch_name)
  @logger.outputters << Log4r::Outputter.stdout unless disable_stdout
  if BatchManager.save_log?
    @log_file = prepare_log_file(batch_name, is_wet)
    @logger.outputters << Log4r::FileOutputter.new(File.basename(@log_file, ".log"), :filename => @log_file)
  end
  BatchManager.logger = self
end

Instance Attribute Details

#log_fileObject (readonly)

Returns the value of attribute log_file.



6
7
8
# File 'lib/batch_manager/logger.rb', line 6

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/batch_manager/logger.rb', line 5

def logger
  @logger
end

Class Method Details

.log_file_path(batch_name, is_wet = false) ⇒ Object



10
11
12
13
# File 'lib/batch_manager/logger.rb', line 10

def log_file_path(batch_name, is_wet = false)
  log_file_name = is_wet ? "#{batch_name}_wet" : batch_name
  File.join(BatchManager.log_dir, log_file_name) + ".log"
end

Instance Method Details

#closeObject



36
37
38
# File 'lib/batch_manager/logger.rb', line 36

def close
  BatchManager.logger = nil
end

#prepare_log_file(batch_name, is_wet) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/batch_manager/logger.rb', line 26

def prepare_log_file(batch_name, is_wet)
  file_path = self.class.log_file_path(batch_name, is_wet)
  unless File.exist?(file_path)
    FileUtils.mkdir_p(File.dirname(file_path), :mode => 0775)
    FileUtils.touch(file_path)
    FileUtils.chmod(0664, file_path)
  end
  file_path
end