import os import sys import json import logging with open("config.json", "r") as f: config = json.load(f) # fix for logging level default_logging_fallback = False if type(config["logging"]["level"]) is not int: try: config["logging"]["level"] = getattr(logging, config["logging"]["level"]) except: config["logging"]["level"] = logging.INFO default_logging_fallback = True # Setup logging settings logging_handlers = [logging.StreamHandler(sys.stdout)] if len(config["log_file"]): logging_handlers.append(logging.FileHandler(config["log_file"])) logging.basicConfig(**config["logging"], handlers = logging_handlers) logging.debug("glob.configured logger") if default_logging_fallback: logging.warning("Invalid logging value in config! Defaulting to logging level INFO.") logging.info("Logging level: %d" % config["logging"]["level"]) # Create save_path if not exists if not os.path.exists(config["save_path"]): os.makedirs(config["save_path"], 0o770)