Log to stdout and a file at the same time
Ruby's Logger class is really useful and handy - you should definitely use it instead of puts
or STDOUT <<
.
One limitation is that you can't log to two destinations at once. Or can you?
log = Logger.new("| tee test.log") # note the pipe ( '|' )
log.info "hi" # will log to both STDOUT and test.log
Handy if you want to track progress of a script while it is running and have a permanent (well...) record of that progress for later inspection.
Written by Łukasz Korecki
Related protips
3 Responses
Seems a better option:
http://stackoverflow.com/questions/6407141/how-can-i-have-ruby-logger-log-output-to-stdout-as-well-as-file
over 1 year ago
·
+1
over 1 year ago
·
It doesn't append the logfile btw, It always overrides... :(
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#