Created
January 22, 2021 07:42
-
-
Save kquick/d554a8b4de5541eb48c0bc1b14080fff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
trylog=" | |
def trylog(l): | |
for e in range(0,50,10): | |
l.log(e, 'level %s'%e) | |
" | |
script() { # $1 is logdict | |
cat <<EOF | |
import logging | |
import logging.config | |
${trylog} | |
${1} | |
print('::root') | |
trylog(logging) | |
print('::one') | |
trylog(logging.getLogger('one')) | |
print('end') | |
print() | |
EOF | |
} | |
echo ":::: Use default logging config" | |
python <<< $(script "pass") | |
echo ":::: Configure both root and logger level" | |
python <<< $(script "logging.config.dictConfig({'version': 1, | |
'root':{'level':logging.INFO}, | |
'loggers':{'one':{'level': logging.WARNING}}})") | |
echo ":::: Configure root level, logger is NOTSET" | |
python <<< $(script "logging.config.dictConfig({'version': 1, | |
'root':{'level':logging.INFO}, | |
'loggers':{'one':{'level': logging.NOTSET}}})") | |
echo ":::: No root level, logger is NOTSET" | |
python <<< $(script "logging.config.dictConfig({'version': 1, | |
'loggers':{'one':{'level': logging.NOTSET}}})") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had some trouble running the shell script, so I broke it out into a more verbose python program and ran it 5 times, please view the gist and output in the comment at the end.
https://gist.github.com/todd-cook/883662ba19eb5a3bb8b372733ec7f6a4