class Fvalve::Fvalve
Constants
- LOG_ERROR
- LOG_INFO
- LOG_WARN
Public Class Methods
log(msg, level = LOG_INFO)
click to toggle source
# File lib/fvalve.rb, line 8 def self.log(msg, level = LOG_INFO) t = Time.now puts "[#{t.strftime("%Y/%m/%d %H:%M:%S %Z")}] [#{level}] #{msg}" end
loge(msg)
click to toggle source
# File lib/fvalve.rb, line 21 def self.loge(msg) self.log msg, LOG_ERROR end
logi(msg)
click to toggle source
# File lib/fvalve.rb, line 13 def self.logi(msg) self.log msg, LOG_INFO end
logw(msg)
click to toggle source
# File lib/fvalve.rb, line 17 def self.logw(msg) self.log msg, LOG_WARN end
new()
click to toggle source
# File lib/fvalve.rb, line 25 def initialize @target_dir = nil @pattern = "*.log" @generations = -1 end
Public Instance Methods
execute()
click to toggle source
# File lib/fvalve.rb, line 31 def execute Fvalve.logi "Started." Fvalve.logi "Parameters:" Fvalve.logi " target_dir: #{@target_dir}" Fvalve.logi " pattern: #{@pattern}" Fvalve.logi " generations: #{@generations}" if !Dir.exist?(@target_dir) then Fvalve.loge "Target directory not found: #{@target_dir}" exit 1 end cwd = Dir.getwd Dir.chdir(@target_dir) gen = 0 deleted = 0 Dir.glob(@pattern).sort {|a, b| b <=> a}.each do |f| gen = gen + 1 if @generations.to_i < gen then Fvalve.logi "Remove file: #{f}" File.delete f deleted = deleted + 1 end end Dir.chdir(cwd) Fvalve.logi "Deleted #{deleted} file(s)." Fvalve.logi "Done." end