Mercurial > repos > yating-l > jbrowsearchivecreator
comparison util/Logger.py @ 25:31a41ce128cc draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
| author | yating-l |
|---|---|
| date | Fri, 13 Oct 2017 12:44:31 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 24:bb6fdccef474 | 25:31a41ce128cc |
|---|---|
| 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 |
