Python/Logging: Difference between revisions
< Python
Jump to navigation
Jump to search
(Created page with "<source lang="python"> import yaml import logging </source>") |
No edit summary |
||
| Line 2: | Line 2: | ||
import yaml | import yaml | ||
import logging | import logging | ||
cfg_yaml = '{}/conf/logging.yaml'.format(get_package_dir()) | |||
with open(cfg_yaml, 'r') as cfg_file: | |||
cfg_dict = yaml.load(open(cfg_yaml, 'r'), Loader=yaml.SafeLoader) | |||
for name in cfg_dict['handlers']: | |||
handler = cfg_dict['handlers'][name] | |||
if 'filename' in handler and handler['filename'].startswith('~'): | |||
handler['filename'] = os.path.expanduser(handler['filename']) | |||
logging.config.dictConfig(cfg_dict) | |||
</source> | </source> | ||
Revision as of 07:21, 2 October 2019
import yaml
import logging
cfg_yaml = '{}/conf/logging.yaml'.format(get_package_dir())
with open(cfg_yaml, 'r') as cfg_file:
cfg_dict = yaml.load(open(cfg_yaml, 'r'), Loader=yaml.SafeLoader)
for name in cfg_dict['handlers']:
handler = cfg_dict['handlers'][name]
if 'filename' in handler and handler['filename'].startswith('~'):
handler['filename'] = os.path.expanduser(handler['filename'])
logging.config.dictConfig(cfg_dict)