1

I am running the following code in a custom Python application:

if __name__ == '__main__':
    logging.basicConfig(filemode='example.log', level=logging.DEBUG)
    logging.debug('This message should go to the log file')

but the output is being written to standard out. I ran the same code from a Jupyter notebook and it creates the example.log file and writes the log message to it.

I read that the order of imports may be important. Here is the order:

import logging
import argparse
import time
import os
import sys
import json

1 Answer 1

1

You made a typo in the arguments to basicConfig.

Instead of setting filename to example.log, you set filemode, which is something else!

It worked for me like this:

import logging

if __name__ == '__main__':
    logging.basicConfig(filename='example.log', level=logging.DEBUG)
    logging.debug('This message should go to the log file')
Sign up to request clarification or add additional context in comments.

1 Comment

haha yup, just realized that as well. Wish there was a better way to have figured that out than just by skimming over the code over and over.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.