diff --git a/requirements.txt b/requirements.txt index cc8e70ee..030b0986 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ accept aioamqp git+https://github.com/LukeXuan/aiosmtplib # custom aiosmtlib with ssl support pytz -colorlog +coloredlogs httpagentparser geoip2 GitPython diff --git a/vj4/server.py b/vj4/server.py index f5902553..13551c60 100644 --- a/vj4/server.py +++ b/vj4/server.py @@ -1,6 +1,6 @@ import atexit +import coloredlogs import logging -import logging.config import os import signal import socket @@ -13,41 +13,15 @@ options.define('listen', default='http://127.0.0.1:8888', help='Server listening address.') options.define('prefork', default=1, help='Number of prefork workers.') -options.define('log_format', - default=('%(log_color)s[%(levelname).1s ' - '%(asctime)s %(module)s:%(lineno)d]%(reset)s %(message)s'), - help='Log format.') _logger = logging.getLogger(__name__) def main(): - logging.config.dictConfig({ - 'version': 1, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - 'formatter': 'colored', - }, - }, - 'formatters': { - 'colored': { - '()': 'colorlog.ColoredFormatter', - 'format': options.log_format, - 'datefmt': '%y%m%d %H:%M:%S' - } - }, - 'root': { - 'level': 'DEBUG' if options.debug else 'INFO', - 'handlers': ['console'], - }, - 'loggers': { - 'sockjs': { - 'level': 'WARNING', - }, - }, - 'disable_existing_loggers': False, - }) + coloredlogs.install(level=logging.DEBUG if options.debug else logging.INFO, + fmt='[%(levelname).1s %(asctime)s %(module)s:%(lineno)d] %(message)s', + datefmt='%y%m%d %H:%M:%S') + logging.getLogger('sockjs').setLevel(logging.WARNING) url = urllib.parse.urlparse(options.listen) if url.scheme == 'http': sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) diff --git a/vj4/util/argmethod.py b/vj4/util/argmethod.py index 5b194a4c..7f81bbe1 100644 --- a/vj4/util/argmethod.py +++ b/vj4/util/argmethod.py @@ -8,8 +8,6 @@ python3.5 -m vj4.model.user --db-name=prod get -1 """ import collections -import logging -import logging.config from vj4 import db from vj4.util import options @@ -26,32 +24,13 @@ def wrap(method): def invoke_by_args(): - logging.config.dictConfig({ - 'version': 1, - 'handlers': { - 'console': { - 'class': 'logging.StreamHandler', - 'formatter': 'colored', - }, - }, - 'formatters': { - 'colored': { - '()': 'colorlog.ColoredFormatter', - 'format': '%(log_color)s[%(levelname).1s ' - '%(asctime)s %(module)s:%(lineno)d]%(reset)s %(message)s', - 'datefmt': '%y%m%d %H:%M:%S' - } - }, - 'root': { - 'level': 'INFO', - 'handlers': ['console'], - }, - 'disable_existing_loggers': False, - }) import argparse import asyncio + import coloredlogs import inspect import pprint + coloredlogs.install(fmt='[%(levelname).1s %(asctime)s %(module)s:%(lineno)d] %(message)s', + datefmt='%y%m%d %H:%M:%S') parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='') for name, method in _methods.items():