Commit 5918e30266834b0f2f1ae83720537794948a23ea

Authored by hitier
1 parent 8105f7da

Set loglevel from configfile

Showing 1 changed file with 3 additions and 7 deletions   Show diff stats
app/__init__.py
... ... @@ -16,7 +16,6 @@ app_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), '..')
16 16 env_file = os.path.join(app_dir, ".flaskenv")
17 17 load_dotenv(env_file, verbose=True)
18 18  
19   -
20 19 login_manager = LoginManager()
21 20  
22 21 login_manager.login_view = "auth.login"
... ... @@ -70,26 +69,23 @@ def create_app(config_class=None):
70 69  
71 70 app.logger.removeHandler(default_handler)
72 71  
73   - logs_dir = os.path.join(app_dir, 'logs')
74   - logs_file = os.path.join(logs_dir, 'pdc.log')
75   -
76 72 # Log to stdout
77 73 if app.debug or app.testing or app.config['LOG_TO_STDOUT']:
78 74 stream_handler = logging.StreamHandler()
79   - stream_handler.setLevel(logging.INFO)
80 75 app.logger.addHandler(stream_handler)
81 76 # or log to file
82 77 # TODO: get filename from config
83 78 else:
  79 + logs_file = app.config['PDC_LOGS_FILE']
  80 + logs_dir = os.path.dirname(logs_file)
84 81 if not os.path.exists(logs_dir):
85 82 os.mkdir(logs_dir)
86 83 file_handler = RotatingFileHandler(logs_file, maxBytes=10240, backupCount=10)
87 84 file_handler.setFormatter(logging.Formatter(
88 85 '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]'))
89   - file_handler.setLevel(logging.INFO)
90 86 app.logger.addHandler(file_handler)
91 87  
92   - app.logger.setLevel(logging.INFO)
  88 + app.logger.setLevel(app.config['PDC_LOGS_LEVEL'])
93 89 app.logger.info("Starting PDC-WEB")
94 90  
95 91 db.init_app(app)
... ...