From 7e08aa0ce2f1b0fddbf054c414d617ff406715e2 Mon Sep 17 00:00:00 2001 From: Richard Hitier Date: Wed, 24 Mar 2021 09:04:35 +0100 Subject: [PATCH] Allow force logging to stdout --- app/__init__.py | 12 ++++++------ pdc_config.py | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 99ffcd3..156a792 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -2,13 +2,13 @@ import os import sys from flask import Flask -from flask.logging import default_handler from flask_login import LoginManager -from app.models import db, User - import logging -from logging.handlers import SMTPHandler, RotatingFileHandler +from logging.handlers import RotatingFileHandler +from flask.logging import default_handler + +from app.models import db, User login_manager = LoginManager() @@ -64,7 +64,7 @@ def create_app(config_class=None): app.logger.removeHandler(default_handler) # Log to stdout - if False: #app.debug or app.testing or app.config['LOG_TO_STDOUT']: + if app.debug or app.testing or app.config['LOG_TO_STDOUT']: stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) app.logger.addHandler(stream_handler) @@ -73,7 +73,7 @@ def create_app(config_class=None): else: if not os.path.exists('logs'): os.mkdir('logs') - file_handler = RotatingFileHandler('logs/pdc.log', maxBytes=10240, backupCount=10) + file_handler = RotatingFileHandler('logs/pdc.log')#, maxBytes=10240, backupCount=10) file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) file_handler.setLevel(logging.INFO) diff --git a/pdc_config.py b/pdc_config.py index 030a38b..595ad70 100644 --- a/pdc_config.py +++ b/pdc_config.py @@ -12,6 +12,12 @@ class Config(object): SECRET_KEY = 'dev' SQLALCHEMY_TRACK_MODIFICATIONS = False + # You can force logging to stdout in production environment + # (make sure your httpd/wsgi server can redirect to log files) + LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT') + if LOG_TO_STDOUT and LOG_TO_STDOUT.upper() == "true".upper(): + LOG_TO_STDOUT = True + # Trying to set specific db uri from ./db_config.py try: SQLALCHEMY_DATABASE_URI = sqlalchemy_database_uri -- libgit2 0.21.2