Skip to content

Instantly share code, notes, and snippets.

@kquick
Created January 22, 2021 07:42
Show Gist options
  • Save kquick/d554a8b4de5541eb48c0bc1b14080fff to your computer and use it in GitHub Desktop.
Save kquick/d554a8b4de5541eb48c0bc1b14080fff to your computer and use it in GitHub Desktop.
#!/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}}})")
@todd-cook
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment