Created
August 22, 2013 19:07
-
-
Save JEG2/6311432 to your computer and use it in GitHub Desktop.
Showing Josh how MRI works.
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
~/Desktop [ruby 2.0.0p247]$ cat dont_close_my_logger.rb | |
require "logger" | |
log = ARGV.shift or abort "USAGE: #{$PROGRAM_NAME} LOG" | |
logger = Logger.new(log) | |
threads = [ ] | |
threads << Thread.new do | |
logger.info "Thread one started. Sleeping a bit to make sure thread two is going..." | |
sleep 1 | |
logger.info "Exiting thread one." | |
end | |
threads << Thread.new do | |
logger.info "Thread two started. Sleeping to make sure thread one stops..." | |
sleep 3 | |
logger.info "Exiting thread two." | |
end | |
threads.each(&:join) | |
~/Desktop [ruby 2.0.0p247]$ ruby -v dont_close_my_logger.rb result.log | |
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0] | |
~/Desktop [ruby 2.0.0p247]$ cat result.log | |
# Logfile created on 2013-08-22 14:05:12 -0500 by logger.rb/36483 | |
I, [2013-08-22T14:05:12.533654 #13569] INFO -- : Thread one started. Sleeping a bit to make sure thread two is going... | |
I, [2013-08-22T14:05:12.533786 #13569] INFO -- : Thread two started. Sleeping to make sure thread one stops... | |
I, [2013-08-22T14:05:13.534145 #13569] INFO -- : Exiting thread one. | |
I, [2013-08-22T14:05:15.534440 #13569] INFO -- : Exiting thread two. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment