| 1 | import logging |
| 2 | |
| 3 | def main(): |
| 4 | # Configure the logging system |
| 5 | logging.basicConfig( |
| 6 | filename='app.log', |
| 7 | level=logging.ERROR |
| 8 | ) |
| 9 | |
| 10 | # Variables (to make the calls that follow work) |
| 11 | hostname = 'www.python.org' |
| 12 | item = 'spam' |
| 13 | filename = 'data.csv' |
| 14 | mode = 'r' |
| 15 | |
| 16 | # Example logging calls (insert into your program) |
| 17 | logging.critical('Host %s unknown', hostname) |
| 18 | logging.error("Couldn't find %r", item) |
| 19 | logging.warning('Feature is deprecated') |
| 20 | logging.info('Opening file %r, mode=%r', filename, mode) |
| 21 | logging.debug('Got here') |
| 22 | |
| 23 | if __name__ == '__main__': |
| 24 | main() |