From: Robert Klemme Date: 2010-10-15T00:45:35+09:00 Subject: Re: How to overwrite standard puts method On 14.10.2010 10:08, Arkady Itkin wrote: > Robert Klemme wrote in post #949915: >> On 10/13/2010 07:31 PM, Arkady Itkin wrote: >>> buildR output? >> There are several methods that write to stdout (off the top of my head >> at least puts, print, printf). One option would be to assign to $stdout >> another stream. If you want to catch child process output things get a >> bit more complicated. In that case you either need to use IO#popen to >> handle child process output or open a pipe and use $stdout.reopen to >> attach the write end of the pipe to the stream. You then need to read >> (asynchronously, i.e. in a thread) from the read end. >> >> Btw, why is offline filtering not an option? I mean, if you write >> stdout to a file you can filter whatever you like and you still have the >> whole output. >> > It looks like I did not explain my problem correctly. > > I'm trying to debug a huge amount of buildR code which overflows me with > tons of information printed out. > Of course, I can redirect it to the file (both from within the code or > from command prompt) and then try to filter out the needed information > from the saved output. But since the output it's not well > organized/structured it's not an easy task. > > I thought about replacing all puts/print etc. calls that exists in the > code by log4R which can be controlled from outside (and, on the way > provide better structured output). What kind of structure do you expect to get? As far as I can see changing puts to internally delegate to a Logger can give you only timestamp and maybe thread id because puts itself only accepts message texts. You can especially *not* get log levels with this approach. > Of course, I can find and replace puts/sprints etc. in the code to my > method. But this is huge amount of code and I'm lazy :-). > > So, I thought about some trick which will allow me to overwrite standard > output methods like puts and get control of the output into my code > where I can do whatever I want. It may be useful for other people as > well when they need to debug the build code. Yes, of course you can do that. But I still wonder what kind of structure beyond added timestamps you expect. > BTW, any other idea on how to debug buildR code will be appreciated. I > tried to use ruby debugger with it but it fails in attempt to load > buildR stuff. Whenever I need to debug an ant build I use option -d (debug, really verbose), let all output flow into a file and look at it with my favorite text editor [1]. That supports setting bookmarks based on search patterns (POSIX regexp), you can copy all bookmarked lines into a new document etc. Cheers robert [1] http://www.textpad.com/ -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/