logging.basicConfig(
filename=f"{output_location}/log.txt",
format="{asctime} - {levelname} - {filename}: {message}",
datefmt = "%d %b %H:%M",
style="{",
level=logging.INFO
)
This is my code and it used to work just fine but after I changed a line of code it stopped working. Outcome before it stopped working:
- Have the updated logging format as specified by the format parameter.
- Have the file
log.txtcreated with the logs in it.
Now the logs look like this: WARNING:root when the format parameter says otherwise. In additon the log.txt file is not created.
The line of code I changed is output_location = os.getcwd() + r"/../output" where it is changed from r"/output" to r"/../output". This line of code is in this function:
def create_output_dir() -> Path:
"""Creates the output directory where all the log files and user facing sheets will go."""
output_location = os.getcwd() + r"/output"
path = Path(output_location)
if not path.exists():
msg = "A folder named 'output' has been created. All files generated will go there."
print(msg)
logging.info(msg)
path.mkdir()
return path
After I reverted the code to remove the /.. part the logging format stays as the default which is WARNING:root. I'm not entirely sure what happened but it just stopped working out of nowhere.
basicConfig()only applies the config if there is no other logging config yet.