Class: BatchManager::Logger
- Inherits:
-
Object
- Object
- BatchManager::Logger
- Defined in:
- lib/batch_manager/logger.rb
Instance Attribute Summary collapse
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(batch_name, is_wet, disable_stdout = false) ⇒ Logger
constructor
A new instance of Logger.
- #prepare_log_file(batch_name, is_wet) ⇒ Object
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_file ⇒ Object (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 |
#logger ⇒ Object
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
#close ⇒ Object
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 |