I want to number/count my log messages in Python using the logging module. I would like this counter to start at 1 for each logger level.
Right now I have the following configuration:
logging.basicConfig(level=logging.INFO,
format='%(asctime)s MyAppName %(levelname)s %(message)s',
datefmt="[%Y-%m-%d %H:%M:%S]")
logging.info("Entering step 1")
logging.info("Finishing step 1")
logging.info("Exiting code")
and I get this
[2021-06-10 18:01:57] MyAppName INFO Entering step 1
[2021-06-10 18:01:58] MyAppName INFO Finishing step 1
[2021-06-10 18:01:59] MyAppName INFO Exiting code
How can I easily change it, so I get the following:
[2021-06-10 18:01:57] MyAppName INFO [1] Entering step 1
[2021-06-10 18:01:58] MyAppName INFO [2] Finishing step 1
[2021-06-10 18:01:59] MyAppName INFO [3] Exiting code