hello
razmeth and welcome to the monastery
the key concept behind your question is multiplexing.
Follow in your production code the wiser advices you already received but, in the case you want to explore that way and reinvent the wheel (
see my sgnature..) you can have a look at my attempt to do exactly the same thing:
Multiplexing log output: Log4perl of the poors
Also
Loops's attempt at
Output to STDOUT and print last line to console is reach of useful hints.
Hth
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.