Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import logging
- import logging.config
- import traceback
- import warnings
- class Formatter(logging.Formatter):
- def format(self, record):
- record.stack_info = ''.join(traceback.format_stack())
- return super().format(record)
- def configure_logging():
- warning_logger_name = 'py.warnings'
- logging.captureWarnings(True)
- logging.config.dictConfig({
- 'formatters': {
- 'f': {
- '()': '__main__.Formatter',
- 'format': '%(name)s\n'
- '%(pathname)s\n'
- '%(lineno)d\n'
- '%(message)s',
- },
- },
- 'handlers': {
- 'h': {
- 'level':'WARN',
- 'class':'logging.StreamHandler',
- 'formatter':'f',
- },
- },
- 'loggers': {
- warning_logger_name: {
- 'handlers': ['h'],
- },
- },
- 'version': 1,
- })
- def main():
- f1()
- def f1():
- f2()
- def f2():
- f3()
- def f3():
- warnings.warn('f3() warning')
- if __name__ == '__main__':
- configure_logging()
- main()
Add Comment
Please, Sign In to add comment