From e82d97ecf63ae561e2bd38ab2376cb45c50ff88c Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 17 2018 12:13:11 +0000 Subject: Add logging to mdapi This allows to have a better idea of what is going on on the server side of things as before it wasn't doing much or anything actually. Signed-off-by: Pierre-Yves Chibon --- diff --git a/mdapi/__init__.py b/mdapi/__init__.py index aad9b2e..3c56044 100644 --- a/mdapi/__init__.py +++ b/mdapi/__init__.py @@ -24,6 +24,8 @@ Top level of the mdapi aiohttp application. ''' import functools import json +import logging +import logging.config import os import urllib from urllib.parse import parse_qs @@ -57,6 +59,9 @@ with open(indexfile) as stream: INDEX = INDEX.replace('$PREFIX', CONFIG.get('PREFIX', '')) +_log = logging.getLogger(__name__) + + def allows_jsonp(function): ''' Add support for JSONP queries to the endpoint decorated. ''' @@ -206,6 +211,7 @@ def _expand_pkg_info(pkgs, branch, repotype=None): @asyncio.coroutine @allows_jsonp def get_pkg(request): + _log.info('get_pkg %s', request) branch = request.match_info.get('branch') pretty = _get_pretty(request) name = request.match_info.get('name') @@ -226,6 +232,7 @@ def get_pkg(request): @asyncio.coroutine @allows_jsonp def get_src_pkg(request): + _log.info('get_src_pkg %s', request) branch = request.match_info.get('branch') pretty = _get_pretty(request) name = request.match_info.get('name') @@ -245,6 +252,7 @@ def get_src_pkg(request): @asyncio.coroutine @allows_jsonp def get_pkg_files(request): + _log.info('get_pkg_files %s', request) branch = request.match_info.get('branch') name = request.match_info.get('name') pretty = _get_pretty(request) @@ -277,6 +285,7 @@ def get_pkg_files(request): @asyncio.coroutine @allows_jsonp def get_pkg_changelog(request): + _log.info('get_pkg_changelog %s', request) branch = request.match_info.get('branch') name = request.match_info.get('name') pretty = _get_pretty(request) @@ -310,6 +319,7 @@ def get_pkg_changelog(request): def list_branches(request): ''' Return the list of all branches currently supported by mdapi ''' + _log.info('list_branches: %s', request) pretty = _get_pretty(request) output = sorted(list(set([ # Remove the front part `mdapi-` and the end part -.sqlite @@ -348,6 +358,7 @@ def process_dep(request, action): ''' Return the information about the packages having the specified action (provides, requires, obsoletes...) ''' + _log.info('process_dep %s: %s', action, request) branch = request.match_info.get('branch') pretty = _get_pretty(request) name = request.match_info.get('name') @@ -409,6 +420,7 @@ def get_supplements(request): @asyncio.coroutine def index(request): + _log.info('index %s', request) return web.Response( body=INDEX.encode('utf-8'), content_type='text/html', @@ -417,6 +429,9 @@ def index(request): @asyncio.coroutine def init(loop): + logging.basicConfig() + logging.config.dictConfig(CONFIG.get('LOGGING') or {'version': 1}) + app = web.Application(loop=loop) routes = [] prefix = CONFIG.get('PREFIX', '') diff --git a/mdapi/default_config.py b/mdapi/default_config.py index 7ea6f9d..2757562 100644 --- a/mdapi/default_config.py +++ b/mdapi/default_config.py @@ -25,3 +25,34 @@ mdapi default configuration. # url to the database server: DB_FOLDER = '/var/tmp' + +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'formatters': { + 'standard': { + 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' + }, + }, + 'handlers': { + 'console': { + 'level': 'INFO', + 'formatter': 'standard', + 'class': 'logging.StreamHandler', + 'stream': 'ext://sys.stdout', + }, + }, + # The root logger configuration; this is a catch-all configuration + # that applies to all log messages not handled by a different logger + 'root': { + 'level': 'INFO', + 'handlers': ['console'], + }, + 'loggers': { + 'sqlalchemy': { + 'handlers': ['console'], + 'level': 'WARN', + 'propagate': False + } + } +}