Merge pull request #91 from dirtbags/90-add-better-logging-to-devel-server

90 add better logging to devel server
This commit is contained in:
int00h5525 2019-10-30 11:09:50 -05:00 committed by GitHub
commit 2082100fc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -265,12 +265,24 @@ if __name__ == '__main__':
'--base', default="", '--base', default="",
help="Base URL to this server, for reverse proxy setup" 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() args = parser.parse_args()
parts = args.bind.split(":") parts = args.bind.split(":")
addr = parts[0] or "0.0.0.0" addr = parts[0] or "0.0.0.0"
port = int(parts[1]) 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 = MothServer((addr, port), MothRequestHandler)
server.args["base_url"] = args.base server.args["base_url"] = args.base

View File

@ -8,6 +8,7 @@ import hashlib
import html import html
import io import io
import importlib.machinery import importlib.machinery
import logging
import mistune import mistune
import os import os
import random import random
@ -19,6 +20,8 @@ import yaml
messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' messageChars = b'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
LOGGER = logging.getLogger(__name__)
def djb2hash(str): def djb2hash(str):
h = 5381 h = 5381
for c in str.encode("utf-8"): for c in str.encode("utf-8"):
@ -28,6 +31,7 @@ def djb2hash(str):
@contextlib.contextmanager @contextlib.contextmanager
def pushd(newdir): def pushd(newdir):
curdir = os.getcwd() curdir = os.getcwd()
LOGGER.debug("Attempting to chdir from %s to %s" % (curdir, newdir))
os.chdir(newdir) os.chdir(newdir)
# Force a copy of the old path, instead of just a reference # Force a copy of the old path, instead of just a reference
@ -48,6 +52,7 @@ def pushd(newdir):
del(sys.modules[module]) del(sys.modules[module])
sys.path = old_path sys.path = old_path
LOGGER.debug("Changing directory back from %s to %s" % (newdir, curdir))
os.chdir(curdir) os.chdir(curdir)
@ -154,8 +159,10 @@ class Puzzle:
stream.seek(0) stream.seek(0)
if header == "yaml": if header == "yaml":
LOGGER.info("Puzzle is YAML-formatted")
self.read_yaml_header(stream) self.read_yaml_header(stream)
elif header == "moth": elif header == "moth":
LOGGER.info("Puzzle is MOTH-formatted")
self.read_moth_header(stream) self.read_moth_header(stream)
for line in stream: for line in stream:
@ -190,6 +197,7 @@ class Puzzle:
self.handle_header_key(key, val) self.handle_header_key(key, val)
def handle_header_key(self, key, val): def handle_header_key(self, key, val):
LOGGER.debug("Handling key: %s, value: %s", key, val)
if key == 'author': if key == 'author':
self.authors.append(val) self.authors.append(val)
elif key == 'summary': elif key == 'summary':
@ -213,6 +221,7 @@ class Puzzle:
parts = shlex.split(val) parts = shlex.split(val)
name = parts[0] name = parts[0]
hidden = False hidden = False
LOGGER.debug("Attempting to open %s", os.path.abspath(name))
stream = open(name, 'rb') stream = open(name, 'rb')
try: try:
name = parts[1] name = parts[1]