class Zold::Node::NohupLog
Log
facility for nohup
Public Class Methods
new(file, max)
click to toggle source
# File lib/zold/commands/node.rb, line 490 def initialize(file, max) @file = file raise "Truncation size is too small (#{max}), should be over 10Kb" if max < 10 * 1024 @max = max end
Public Instance Methods
copy(source, target, start = 0)
click to toggle source
# File lib/zold/commands/node.rb, line 511 def copy(source, target, start = 0) total = 0 File.open(target, 'w') do |t| File.open(source, 'r').each do |line| next unless total >= start t.print(line) total += 1 end end total end
print(data)
click to toggle source
# File lib/zold/commands/node.rb, line 496 def print(data) File.open(@file, 'a') { |f| f.print(data) } return if File.size(@file) < @max temp = Tempfile.new total = copy(@file, temp) unit = File.size(@file) / total tail = total - @max / (2 * unit) copy(temp, @file, tail) File.delete(temp) File.open(@file, 'a') do |f| f.print("The file was truncated, because it was over the quota of #{@max} bytes, \ #{tail} lines left out of #{total}, average line length was #{unit} bytes\n\n") end end