diff --git a/main.py b/main.py index 50c118a..64a058b 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from math import ceil #from peertube import Cache, PaginatedResults, FailedRequest, API from peertube import * import sys +import logging # Import everything from utils.py, to keep main.py focused # on CLI arguments parsing, and web routes declarations @@ -11,6 +12,17 @@ from utils import * cache = Cache() api = API(cache) +from logging.config import dictConfig + +dictConfig({ + 'version': 1, + 'loggers': { + 'quart.app': { + 'level': 'DEBUG', + }, + }, +}) + # --- WEBSERVER STUFF --- # All utilities are above this point. # Routes are defined below @@ -51,7 +63,7 @@ class Context(): # Helper function to insert/log an error def error(self, reason): - print("[ERROR] %s" % reason) + app.logger.error(reason) self.failures.append(FailedRequest(reason)) return self @@ -81,7 +93,7 @@ class Context(): #print("[DEBUG] Considering future result %s" % repr(key)) if len(self.failures) > 0: # Previous failures, don't run further requests - print("[DEBUG] Previous failures. Skipping future result %s" % repr(key)) + app.logger.debug("Previous failures. Skipping future result %s" % repr(key)) return self # Don't collapse (foo) into foo, keep it tupled if not isinstance(args, tuple): args = (args, ) @@ -110,7 +122,7 @@ class Context(): # Simple key to insert_result result into, whether it succeeded or failed # Special-case: if result is a PaginatedResults, then we insert the total results count into pagination["total"] if isinstance(result, PaginatedResults): - print("Inserting pagination from API request!") + app.logger.debug("Inserting pagination from API request!") self.insert("pagination", { "total": result.total }) return self.insert_result(key, result.data) # Very normal result @@ -132,7 +144,7 @@ class Context(): for entry in range(1, len(arg)): # We take each part of the tuple as a "route" inside the previous result data = data[arg[entry]] - print("[DEBUG] Found previous entry %s at given route: %s" % (arg[0].key(), data)) + app.logger.debug("Found previous entry %s at given route: %s" % (arg[0].key(), data)) return data else: #print("[DEBUG] Found normal argument") @@ -167,7 +179,7 @@ class Context(): return self.error("PROGRAMMING ERROR: pagination.total count not found in current context. Did you really insert_future_result of an API request that produces paginated results?") total_pages = ceil(self.context["pagination"]["total"] / 10) - print("[DEBUG] Found %s pages when paginating %s" % (str(total_pages), results_key)) + app.logger.debug("Found %s pages when paginating %s" % (str(total_pages), results_key)) return self.paginate(url, page, total_pages) # Build instance context (eg. domain and instance_name)