Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
simple configurable logging for one-off scripts
#!/usr/bin/env python
# encoding: utf-8
"""
Call me like this::
python log_example.py
To set the log level::
LOGLEVEL=INFO log_example.py
Lowercase is OK too::
LOGLEVEL=debug log_example.py
"""
import logging
import os
try:
loglevel = getattr(logging, os.environ.get('LOGLEVEL', 'WARN').upper())
except AttributeError:
pass
logging.basicConfig(level=loglevel)
log = logging.getLogger(__name__)
if __name__ == '__main__':
log.debug('this is a debug message')
log.info('this is an info message')
log.warn('this is a warn message')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.