import os | |
import logging | |
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper() | |
logging.basicConfig(level=LOGLEVEL, format="%(asctime)s %(message)s") |
Issue
Initial Question
Damn, it doesn't work but the chance is high that I made the issue on myself.
import logging
logging.config.fileConfig(fname='logging.conf')
logging.basicConfig(level=logging.INFO)
logging.debug('debug logging test')
logging.info('info logging test')
logging.info('error logging test')
In my logging.conf
, I've defined the loglevel with DEBUG.
I hoped that I can configure the loglevel with debug in the logging.conf but configure the real applied log level via an .env
file to keep the "moving parts" in one configuration file.
Sadly my concept with python 3.11 does not work. I still get the debug logging message.
Update - 20230302T10:08:30
Following LOC is doing the trick for me.
# replace this line
logging.basicConfig(level=logging.INFO)
# with that line
logging.getLogger().setLevel(level=os.getenv('MY_LOGGER_LEVEL', 'INFO').upper())
Issue
Initial Question
Damn, it doesn't work but the chance is high that I made the issue on myself.
import logging logging.config.fileConfig(fname='logging.conf') logging.basicConfig(level=logging.INFO) logging.debug('debug logging test') logging.info('info logging test') logging.info('error logging test')In my
logging.conf
, I've defined the loglevel with DEBUG.I hoped that I can configure the loglevel with debug in the logging.conf but configure the real applied log level via an
.env
file to keep the "moving parts" in one configuration file.Sadly my concept with python 3.11 does not work. I still get the debug logging message.
Update - 20230302T10:08:30
Following LOC is doing the trick for me.
# replace this line logging.basicConfig(level=logging.INFO) # with that line logging.getLogger().setLevel(level=os.getenv('MY_LOGGER_LEVEL', 'INFO').upper())
I like the usage of environment variables with default values. Very useful!
👍