-
-
Save juanpabloaj/3e6a41f683c1767c17824811db01165b to your computer and use it in GitHub Desktop.
import os | |
import logging | |
LOGLEVEL = os.environ.get('LOGLEVEL', 'INFO').upper() | |
logging.basicConfig(level=LOGLEVEL, format="%(asctime)s %(message)s") |
just what I needed :)
π
I think this should be the default behavior of the package logging
. It should support setting the LOGLEVEL through env-var natively IMO.
Thank you for this. It is surprisingly difficult to find.
should we open a PEP ?
thanks!!!
π
thank you !
THANKS!
THANKS!
π
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!
Thanks, I was using LOGLEVEL.INFO (an int) and hadn't realized you could just pass a string.