def main(): # logger = logging.getLogger() util.setup_logging() # logger = logging.getLogger(__name__) # send some messages # logger.debug('debug message') # logger.info('info message') logging.debug('debug message') logging.info('info message') logging.warning('warn message') logging.error('error message') logging.critical('critical message') # inner fnc inner_fnc() # run func1 lib1.func1() # run func1 my_module.foo() bar = my_module.Bar() bar.bar()
import os import yaml import logging import logging.config # load my module import my_module # init logging config my_module.setup_logging() my_module.foo() bar = my_module.Bar() bar.bar() bar.barError() logger = logging.getLogger(__name__) logger.info('Some random info message from main.py') try: open('/path/to/does/not/exist', 'rb') except (SystemExit, KeyboardInterrupt): raise except Exception as e: logger.error('Failed to open file', exc_info=True) logger.debug('Debugging something in main')
* as a bonus demonstrate why pylint warns about mutable objects used as default variables Copyright: Red Hat, Inc. 2018 Author: Lukas Doktor <*****@*****.**> License: GPLv3+ """ from pprint import pprint import os import sys sys.path.insert(0, os.path.dirname(__file__)) import my_module pprint(locals()) pprint(dir(my_module)) # And now why you shouldn't be using mutable objects? params1 = my_module.bar.don_use_mutable_objects_as_default_parmas() print(params1) params1["foo"] = "bar" bar2 = my_module.Bar() params2 = bar2.don_use_mutable_objects_as_default_parmas() print(params2) params2["One or two beers are literally"] = "12 beers" print(my_module.bar.don_use_mutable_objects_as_default_parmas())