Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import re 

2import os 

3import yaml 

4import ujson as json 

5import logging 

6import logging.config 

7 

8import coloredlogs 

9 

10def findfile(pattern, *folders): 

11 regexp = re.compile(pattern) 

12 folders = ['.', *folders, os.path.dirname(__file__)] 

13 for top in folders: 

14 for root, _, files in os.walk(top): 

15 for name in files: 

16 if regexp.match(name): 

17 filename = os.path.join(root, name) 

18 return filename 

19 

20def get_logconfig(config_file='logging.yaml', *folders): 

21 "Load the log config file" 

22 filename = findfile(config_file, *folders) 

23 

24 ext = os.path.splitext(filename)[-1] 

25 loader = {'.yaml': yaml.load, '.json': json.load} 

26 

27 with open(filename, 'r') as stream: 

28 log_config = loader[ext](stream) 

29 return log_config 

30 

31def setup_config(config_file='logging.yaml', *folders): 

32 config = get_logconfig(config_file, *folders) 

33 logging.config.dictConfig(config) 

34 return config