class Logger

Defined in:

interact/logger.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(command : String, log_name : String, sleept : Float64 = 0.01) #

command is the bash command that you want to run and capture the output of. @log_name is the name of the log file you want to temporarily create. @sleept is the time you want to wait before rechecking if the command has started yet, probably something you don't want to worry about


[View source]

Instance Method Detail

def start(delete_file = true, &) : Bool #

Run @command in the background and pipe its output to the log file, with something constantly monitoring the log file and yielding each new line to the block call. Useful for changing the output of binaries you don't have much control over. Note that the created temp log will be deleted unless the command fails its exit or .start is called with delete_file: false

l = Logger.new(".temp.log", %(echo "CIA spying" && sleep 2 && echo "new veggie tales season"))
l.start do |output, index|
  case output
  when "CIA spying"
    puts "i sleep"
  when .includes?("veggie tales")
    puts "real shit"
  end
end

[View source]