Module: Fasten::Support::Logger

Included in:
Runner, Worker
Defined in:
lib/fasten/support/logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#log_fileObject

Returns the value of attribute log_file.



12
13
14
# File 'lib/fasten/support/logger.rb', line 12

def log_file
  @log_file
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/fasten/support/logger.rb', line 12

def logger
  @logger
end

Instance Method Details

#close_loggerObject



37
38
39
# File 'lib/fasten/support/logger.rb', line 37

def close_logger
  logger.close if logger.is_a? ::Logger
end

#initialize_logger(log_file: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/fasten/support/logger.rb', line 25

def initialize_logger(log_file: nil)
  if log_file
    self.log_file = log_file
  else
    self.log_file ||= "#{fasten_dir}/log/#{kind}/#{name}.log"
    FileUtils.mkdir_p File.dirname(self.log_file)
  end

  close_logger
  self.logger = ::Logger.new self.log_file, level: Fasten.logger.level, progname: Fasten.logger.progname
end

#log_fin(object, message = nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/fasten/support/logger.rb', line 46

def log_fin(object, message = nil)
  object.fin ||= Time.new
  object.dif = object.fin - object.ini

  log_info "Fin #{object.state} #{object.class} #{object} #{message} in #{object.dif}"
end

#log_ini(object, message = nil) ⇒ Object



41
42
43
44
# File 'lib/fasten/support/logger.rb', line 41

def log_ini(object, message = nil)
  object.ini ||= Time.new
  log_info "Ini #{object.state} #{object.class} #{object} #{message}"
end