Commit 7e08aa0ce2f1b0fddbf054c414d617ff406715e2

Authored by hitier
1 parent f186bcd6

Allow force logging to stdout

Showing 2 changed files with 12 additions and 6 deletions   Show diff stats
app/__init__.py
... ... @@ -2,13 +2,13 @@ import os
2 2 import sys
3 3  
4 4 from flask import Flask
5   -from flask.logging import default_handler
6 5 from flask_login import LoginManager
7 6  
8   -from app.models import db, User
9   -
10 7 import logging
11   -from logging.handlers import SMTPHandler, RotatingFileHandler
  8 +from logging.handlers import RotatingFileHandler
  9 +from flask.logging import default_handler
  10 +
  11 +from app.models import db, User
12 12  
13 13 login_manager = LoginManager()
14 14  
... ... @@ -64,7 +64,7 @@ def create_app(config_class=None):
64 64 app.logger.removeHandler(default_handler)
65 65  
66 66 # Log to stdout
67   - if False: #app.debug or app.testing or app.config['LOG_TO_STDOUT']:
  67 + if app.debug or app.testing or app.config['LOG_TO_STDOUT']:
68 68 stream_handler = logging.StreamHandler()
69 69 stream_handler.setLevel(logging.INFO)
70 70 app.logger.addHandler(stream_handler)
... ... @@ -73,7 +73,7 @@ def create_app(config_class=None):
73 73 else:
74 74 if not os.path.exists('logs'):
75 75 os.mkdir('logs')
76   - file_handler = RotatingFileHandler('logs/pdc.log', maxBytes=10240, backupCount=10)
  76 + file_handler = RotatingFileHandler('logs/pdc.log')#, maxBytes=10240, backupCount=10)
77 77 file_handler.setFormatter(logging.Formatter(
78 78 '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
79 79 file_handler.setLevel(logging.INFO)
... ...
pdc_config.py
... ... @@ -12,6 +12,12 @@ class Config(object):
12 12 SECRET_KEY = 'dev'
13 13 SQLALCHEMY_TRACK_MODIFICATIONS = False
14 14  
  15 + # You can force logging to stdout in production environment
  16 + # (make sure your httpd/wsgi server can redirect to log files)
  17 + LOG_TO_STDOUT = os.environ.get('LOG_TO_STDOUT')
  18 + if LOG_TO_STDOUT and LOG_TO_STDOUT.upper() == "true".upper():
  19 + LOG_TO_STDOUT = True
  20 +
15 21 # Trying to set specific db uri from ./db_config.py
16 22 try:
17 23 SQLALCHEMY_DATABASE_URI = sqlalchemy_database_uri
... ...