I have a python program that uses the logging module to output data to a text file, the problem I have is that the output to the text file works fine when I run the script in PyCharm (the 1-10 values are output to both the console screen and written to Log_Test_File.txt), but when I run the script from the command line only the console output appears (with nothing written to the *.txt file). This occurs in both Ubuntu
or on my Raspberry Pi
.
I'll be running the script on the Pi
automatically on start-up (as sudo), is there a way to configure either the Pi
or the script so that the text output works correctly?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import logging
logging.basicConfig(filename="Log_Test_File.txt",
level=logging.DEBUG,
format='%(levelname)s: %(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S')
i=0
while i<10:
logging.info("Logging test: {}".format(i))
i+=1