Created
September 3, 2010 23:32
-
-
Save timmatheson/564719 to your computer and use it in GitHub Desktop.
HerokuLogger Class, allows you to tail the heroku logs through hackery.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class HerokuLogger | |
| def initialize | |
| @keep_processing = true | |
| @log = nil | |
| stop_tailing = Proc.new do | |
| puts "---------------------- Terminating ------------------------" | |
| @keep_processing = false | |
| end | |
| Signal.trap("INT", stop_tailing) | |
| Signal.trap("TERM", stop_tailing) | |
| end | |
| def process | |
| while @keep_processing | |
| if fetch_log | |
| print @log | |
| else | |
| sleep(2) | |
| end | |
| end | |
| end | |
| def fetch_log | |
| log = `heroku logs` | |
| if new_output?(log) | |
| @log = log | |
| return true | |
| end | |
| false | |
| end | |
| def new_output?(data) | |
| data != @log | |
| end | |
| def self.process | |
| new.process | |
| end | |
| end | |
| HerokuLogger.process |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment