Class: Jfrog::Saas::Log::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/jfrog/saas/log/filemanager.rb

Constant Summary collapse

PROCESS_NAME =
'log_file_purge'

Instance Method Summary collapse

Instance Method Details

#check_and_create_dir(solution, target_path) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/jfrog/saas/log/filemanager.rb', line 11

def check_and_create_dir(solution, target_path)
  sol_tgt_path = "#{target_path}/#{solution}"
  unless File.directory?(sol_tgt_path)
    FileUtils.mkdir_p(sol_tgt_path, verbose: ConfigHandler.instance.log_config.debug_mode)
  end
  sol_tgt_path
end

#purge_dataObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jfrog/saas/log/filemanager.rb', line 19

def purge_data
  Dir["#{ConfigHandler.instance.log_config.target_log_path}/**/*.log"].reject { |i| File.directory?(i) }.each do |file_name|
    created_time = File.ctime(file_name)
    diff_days = created_time.to_date.mjd - (Date.today - ConfigHandler.instance.log_config.log_file_retention_days).mjd
    MessageUtils.instance.log_message(MessageUtils::PURGE_RETAIN_DAYS_FOR_FILE, { "param1": file_name.to_s,
                                                                                  "param2": diff_days.to_s,
                                                                                  "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO,
                                                                                  "#{MessageUtils::SOLUTION}": FileManager::PROCESS_NAME } )
    next unless diff_days.negative?

    File.delete(file_name)
    MessageUtils.instance.log_message(MessageUtils::PURGE_SUCCESS_FOR_FILE, { "param1": file_name.to_s,
                                                                              "#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO,
                                                                              "#{MessageUtils::SOLUTION}": FileManager::PROCESS_NAME } )
  end
end