Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I started playing with the logging module in Python recently. My output gets sent to a log file now. So far, so good. But I'd also like to be able to keep tabs on it in progress, without dealing with different logging file handlers in Python. And I like the general idea of knowing how to redirect things to my shell anyways.

So what I want is to have a way to issue python myscript.py foo bar maybepipe something from the shell, see that log file being created line by line, and still have my log file when finished.

I found Read a file that's actively being written, but I am not sure how the answers provided within translate to this case. Anybody have any suggestions?

Thanks!

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

While not exactly what you want, I think it would be easier for you to simply issue the command:

tail -f logfile

to see the logfile being written to. Also, this is a general approach that works with every program that writes to a logfile but doesn't provide visual progress indication.

share|improve this answer
    
This is probably what I will end up using, although I am currently trying to debug my logging. Thanks! –  verbsintransit Feb 28 '13 at 20:17
add comment

I wonder if you may be looking for something like

python myscript.py | tee log.file 

The "|tee logfile" bit take a copy of the output (from stdout) and dumps it to the file log.file, and also displays it to the console.

share|improve this answer
    
I see. That is what I was looking for, but I did not mention what turns out to be a pertinent detail, which is that myscript.py dynamically names the logfile at startup based on the time. So there will be no way to give that file as an argument to tee as things currently stand. –  verbsintransit Feb 28 '13 at 20:16
    
Actually, I think I misunderstood you then - the tee logfile bit takes the stdout and dumps it to a log file, rather then reads it. tail -f is probably as close as you will get without modifying your script. –  davidgo Mar 1 '13 at 0:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.