Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created August 22, 2013 19:07
Show Gist options
  • Save JEG2/6311432 to your computer and use it in GitHub Desktop.
Save JEG2/6311432 to your computer and use it in GitHub Desktop.
Showing Josh how MRI works.
~/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