diff --git a/devel/devel-server.py b/devel/devel-server.py index 438c0e8..05828fb 100755 --- a/devel/devel-server.py +++ b/devel/devel-server.py @@ -265,12 +265,24 @@ if __name__ == '__main__': '--base', default="", help="Base URL to this server, for reverse proxy setup" ) + parser.add_argument( + "-v", "--verbose", + action="count", + default=1, # Leave at 1, for now, to maintain current default behavior + help="Include more verbose logging. Use multiple flags to increase level", + ) args = parser.parse_args() parts = args.bind.split(":") addr = parts[0] or "0.0.0.0" port = int(parts[1]) + if args.verbose >= 2: + log_level = logging.DEBUG + elif args.verbose == 1: + log_level = logging.INFO + else: + log_level = logging.WARNING - logging.basicConfig(level=logging.INFO) + logging.basicConfig(level=log_level) server = MothServer((addr, port), MothRequestHandler) server.args["base_url"] = args.base diff --git a/devel/moth.py b/devel/moth.py index de6456b..a5e3d00 100644 --- a/devel/moth.py +++ b/devel/moth.py @@ -8,6 +8,7 @@ import hashlib import html import io import importlib.machinery +import logging import mistune import os import random @@ -19,6 +20,8 @@ import yaml messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' +LOGGER = logging.getLogger(__name__) + def djb2hash(str): h = 5381 for c in str.encode("utf-8"): @@ -28,6 +31,7 @@ def djb2hash(str): @contextlib.contextmanager def pushd(newdir): curdir = os.getcwd() + LOGGER.debug("Attempting to chdir from %s to %s" % (curdir, newdir)) os.chdir(newdir) # Force a copy of the old path, instead of just a reference @@ -48,6 +52,7 @@ def pushd(newdir): del(sys.modules[module]) sys.path = old_path + LOGGER.debug("Changing directory back from %s to %s" % (newdir, curdir)) os.chdir(curdir) @@ -154,8 +159,10 @@ class Puzzle: stream.seek(0) if header == "yaml": + LOGGER.info("Puzzle is YAML-formatted") self.read_yaml_header(stream) elif header == "moth": + LOGGER.info("Puzzle is MOTH-formatted") self.read_moth_header(stream) for line in stream: @@ -190,6 +197,7 @@ class Puzzle: self.handle_header_key(key, val) def handle_header_key(self, key, val): + LOGGER.debug("Handling key: %s, value: %s", key, val) if key == 'author': self.authors.append(val) elif key == 'summary': @@ -213,6 +221,7 @@ class Puzzle: parts = shlex.split(val) name = parts[0] hidden = False + LOGGER.debug("Attempting to open %s", os.path.abspath(name)) stream = open(name, 'rb') try: name = parts[1]