0

If I set logging.basicConfig(level=INFO, filename="..."), the only thing I am going to see is the actual message I have put inside logger.info("...").

For example if I write:

logger.info("blah blah blah")

What I am going to see in Console is:

blah blah blah

What I want to see is the program line number of logger.info as well. Something like if let's say logger.info is at line 64 at main.py:

line number 64 main.py: blah blah blah

What I should change to see this in the logger setting of python?

1 Answer 1

3

You can use Python logging formatters to do something like this:

import logging

def main():
    logging.basicConfig(format='{%(pathname)s:%(lineno)d}: %(message)s', level=logging.INFO)

    logging.info('test')

if __name__ == '__main__':
    main()

which outputs

{test.py:6}: test
Sign up to request clarification or add additional context in comments.

Comments

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.