From 62ea8b8913ea31c881cf3c98c3c009d57ffc713b Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sat, 16 Nov 2019 10:09:34 +0100 Subject: [PATCH] Logging to stdout, proposal form #1078 --- cps/logger.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cps/logger.py b/cps/logger.py index 54be25e7..77a721d3 100644 --- a/cps/logger.py +++ b/cps/logger.py @@ -18,6 +18,7 @@ from __future__ import division, print_function, unicode_literals import os +import sys import inspect import logging from logging import Formatter, StreamHandler @@ -34,6 +35,7 @@ DEFAULT_LOG_LEVEL = logging.INFO DEFAULT_LOG_FILE = os.path.join(_CONFIG_DIR, "calibre-web.log") DEFAULT_ACCESS_LOG = os.path.join(_CONFIG_DIR, "access.log") LOG_TO_STDERR = '/dev/stderr' +LOG_TO_STDOUT = '/dev/stdout' logging.addLevelName(logging.WARNING, "WARN") logging.addLevelName(logging.CRITICAL, "CRIT") @@ -112,9 +114,13 @@ def setup(log_file, log_level=None): return logging.debug("logging to %s level %s", log_file, r.level) - if log_file == LOG_TO_STDERR: - file_handler = StreamHandler() - file_handler.baseFilename = LOG_TO_STDERR + if log_file == LOG_TO_STDERR or log_file == LOG_TO_STDOUT: + if log_file == LOG_TO_STDOUT: + file_handler = StreamHandler(sys.stdout) + file_handler.baseFilename = log_file + else: + file_handler = StreamHandler() + file_handler.baseFilename = log_file else: try: file_handler = RotatingFileHandler(log_file, maxBytes=50000, backupCount=2) @@ -164,5 +170,5 @@ class StderrLogger(object): self.log.debug("Logging Error") -# default configuration, before application settngs are applied +# default configuration, before application settings are applied setup(LOG_TO_STDERR, logging.DEBUG if os.environ.get('FLASK_DEBUG') else DEFAULT_LOG_LEVEL)