class Airbrussh::LogFileFormatter
A Pretty formatter that sends its output to a specified log file path. LogFileFormatter takes care of creating the file (and its parent directory) if it does not already exist, opens it for appending, and writes a delimiter message. The file is automatically rotated if it reaches 20 MB.
Attributes
path[R]
Public Class Methods
new(path, formatter_class=SSHKit::Formatter::Pretty)
click to toggle source
Calls superclass method
# File lib/airbrussh/log_file_formatter.rb, line 15 def initialize(path, formatter_class=SSHKit::Formatter::Pretty) @path = path ensure_directory_exists if path.is_a?(String) super(formatter_class.new(log_file_io)) write_delimiter end
Private Instance Methods
ensure_directory_exists()
click to toggle source
# File lib/airbrussh/log_file_formatter.rb, line 34 def ensure_directory_exists FileUtils.mkdir_p(File.dirname(path)) end
log_file_io()
click to toggle source
# File lib/airbrussh/log_file_formatter.rb, line 38 def log_file_io @io ||= ::Logger.new(path, 1, 20_971_520) end
write_delimiter()
click to toggle source
# File lib/airbrussh/log_file_formatter.rb, line 24 def write_delimiter delimiter = [] delimiter << "-" * 75 delimiter << "START #{Time.now} cap #{ARGV.join(' ')}" delimiter << "-" * 75 delimiter.each do |line| write(SSHKit::LogMessage.new(SSHKit::Logger::INFO, line)) end end