Mercurial > repos > yating-l > jbrowsearchivecreator
comparison util/Logger.py @ 6:237707a6b74d draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
author | yating-l |
---|---|
date | Thu, 15 Feb 2018 17:05:05 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:e762f4b9e4bd | 6:237707a6b74d |
---|---|
1 import os | |
2 import sys | |
3 import json | |
4 import logging | |
5 import logging.config | |
6 | |
7 #from util.Filters import TraceBackFormatter | |
8 | |
9 class Logger(object): | |
10 def __init__(self, tool_directory, debug="False", extra_files_path=None): | |
11 self.tool_directory = tool_directory | |
12 self.default_level = logging.INFO | |
13 self.debug = debug | |
14 self.extra_files_path = extra_files_path | |
15 | |
16 def setup_logging(self): | |
17 """Setup logging configuration | |
18 reference: https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/ | |
19 """ | |
20 config_path = os.path.join(self.tool_directory, 'logging.json') | |
21 default_level=logging.INFO | |
22 if self.debug.lower() == "true": | |
23 default_level=logging.DEBUG | |
24 if os.path.exists(config_path): | |
25 with open(config_path, 'rt') as f: | |
26 config = json.load(f) | |
27 config["handlers"]["console"]["level"] = default_level | |
28 if self.extra_files_path: | |
29 for i in config["handlers"]: | |
30 if "filename" in config["handlers"][i]: | |
31 config["handlers"][i]["filename"] = os.path.join(self.extra_files_path, config["handlers"][i]["filename"]) | |
32 logging.config.dictConfig(config) | |
33 else: | |
34 logging.warn("Extra files path is not set. The log files will exist at current working directory instead of final output folder") | |
35 else: | |
36 logging.basicConfig(level=default_level) | |
37 logging.warn("Cannot find logging configuration file!\n") | |
38 |