lib/flashplayer/log_file.rb in flashplayer-10.1.3.pre vs lib/flashplayer/log_file.rb in flashplayer-10.1.6.pre

- old
+ new

@@ -4,16 +4,14 @@ class LogFile attr_accessor :logger def initialize - @config = MMConfig.new @logger = $stdout end def tail thread - @config.create tail_path flashlog_path, thread end private @@ -29,31 +27,40 @@ lines_put = 0 trap("INT") { thread.kill } while thread.alive? do - File.open(path, 'r') do |file| - lines_read = 0 - file.readlines.each do |line| - if(lines_read >= lines_put) - logger.puts "[trace] #{line}" - logger.flush - lines_put += 1 - end - lines_read += 1 - end - end + lines_put = read_from_file path, lines_put logger.flush sleep(0.2) end logger.puts "" logger.puts ">> Exiting from tailing '#{path}' at user request" end + def read_from_file path, lines_put + File.open(path, 'r') do |file| + lines_read = 0 + file.readlines.each do |line| + if(lines_read >= lines_put) + logger.puts "[trace] #{line}" + logger.flush + lines_put += 1 + end + lines_read += 1 + end + end unless !File.exists?(path) + lines_put + end + def flashlog_path - File.join(FlashPlayer.home, 'Logs', 'flashlog.txt') + begin + FlashPlayer.flashlog + rescue FlashPlayer::PathError + "/dev/null" + end end def clear_flashlog_at path File.open(path, 'w') do |f| f.write('') @@ -69,11 +76,9 @@ end end desc "Tail the flashlog.txt and block" -def flashlog args - task args do - reader = FlashPlayer::LogFile.new - reader.tail - end +task :flashlog do + reader = FlashPlayer::LogFile.new + reader.tail end