0

I have a little problem, I use logging library and when script running none of log dose not write into a file. After program finished all logs suddenly appear in file. How to put logs in file in realtime? Sorry for my english.

This is my example code:

import logging, time

logging.basicConfig(filename='C:/testlog.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
logging.debug('This is a log message.')

x = 1
while x < 6:
    time.sleep(1)
    logging.error('Log test: ' + str(x))
    x=x+1
mierzej
  • 843
  • 1
  • 6
  • 4
  • 1
    @PeterWood: The logger is _supposed_ to flush itself (eg see [this answer](http://stackoverflow.com/a/16634444/4014959)), & it does so on Linux. But I guess it's worth trying an explicit flush to see if it makes a difference on Windows. – PM 2Ring Sep 08 '15 at 14:00
  • @mierzej What are you using to view the log? Maybe it doesn't update very often. – Peter Wood Sep 08 '15 at 14:02
  • @PM2Ring I think you're correct, I suspect it's to do with the file buffer, which won't be flushed by calling flush, so discard my comment. – Peter Wood Sep 08 '15 at 14:04
  • Flush dose not work. I tested script on linux and it's work fine, log file updated in realtime. On Windows I use powershell to view log, command: get-content testlog.txt -wait .It seems that a platform problem, if somebody find out how to solve this problem I'll glad, now it is enough for me. Thanks for help! – mierzej Sep 08 '15 at 14:23

0 Answers0