From 6d1a3ccdcc51d33022b02e4abfb4473a042240f9 Mon Sep 17 00:00:00 2001 From: Ozzie Isaacs Date: Sat, 28 Mar 2020 07:13:51 +0100 Subject: [PATCH] Improve logger for windows --- cps/__init__.py | 5 ++--- cps/logger.py | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cps/__init__.py b/cps/__init__.py index 6c241d4f..48926f2c 100755 --- a/cps/__init__.py +++ b/cps/__init__.py @@ -33,11 +33,10 @@ from flask_login import LoginManager from flask_babel import Babel from flask_principal import Principal -from . import logger, cache_buster, cli, config_sql, ub, db, services +from . import config_sql, logger, cache_buster, cli, ub, db from .reverseproxy import ReverseProxied from .server import WebServer - mimetypes.init() mimetypes.add_type('application/xhtml+xml', '.xhtml') mimetypes.add_type('application/epub+zip', '.epub') @@ -62,7 +61,6 @@ lm = LoginManager() lm.login_view = 'web.login' lm.anonymous_user = ub.Anonymous - ub.init_db(cli.settingspath) # pylint: disable=no-member config = config_sql.load_configuration(ub.session) @@ -75,6 +73,7 @@ _BABEL_TRANSLATIONS = set() log = logger.create() +from . import services def create_app(): app.wsgi_app = ReverseProxied(app.wsgi_app) diff --git a/cps/logger.py b/cps/logger.py index 77a721d3..c5b686f2 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -67,6 +67,8 @@ def get_level_name(level): def is_valid_logfile(file_path): + if file_path == LOG_TO_STDERR or file_path == LOG_TO_STDOUT: + return True if not file_path: return True if os.path.isdir(file_path): @@ -105,7 +107,9 @@ def setup(log_file, log_level=None): # avoid spamming the log with debug messages from libraries r.setLevel(log_level) - log_file = _absolute_log_file(log_file, DEFAULT_LOG_FILE) + # Otherwise name get's destroyed on windows + if log_file != LOG_TO_STDERR and log_file != LOG_TO_STDOUT: + log_file = _absolute_log_file(log_file, DEFAULT_LOG_FILE) previous_handler = r.handlers[0] if r.handlers else None if previous_handler: @@ -119,7 +123,7 @@ def setup(log_file, log_level=None): file_handler = StreamHandler(sys.stdout) file_handler.baseFilename = log_file else: - file_handler = StreamHandler() + file_handler = StreamHandler(sys.stderr) file_handler.baseFilename = log_file else: try: