From 3e7554422b7d177e12838882ed0b84878278825e Mon Sep 17 00:00:00 2001 From: dalf Date: Sat, 22 Oct 2016 19:07:37 +0200 Subject: [PATCH] [mod] the environment variable SEARX_DEBUG can override the general.debug value in settings.yml --- searx/__init__.py | 21 ++++++++++++++++++++- searx/webapp.py | 6 +++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/searx/__init__.py b/searx/__init__.py index 7b67a394f..b3abc61ae 100644 --- a/searx/__init__.py +++ b/searx/__init__.py @@ -42,7 +42,26 @@ else: with open(settings_path) as settings_yaml: settings = load(settings_yaml) -if settings.get('general', {}).get('debug'): +''' +enable debug if +the environnement variable SEARX_DEBUG is 1 or true +(whatever the value in settings.yml) +or general.debug=True in settings.yml + +disable debug if +the environnement variable SEARX_DEBUG is 0 or false +(whatever the value in settings.yml) +or general.debug=False in settings.yml +''' +searx_debug_env = environ.get('SEARX_DEBUG', '').lower() +if searx_debug_env == 'true' or searx_debug_env == '1': + searx_debug = True +elif searx_debug_env == 'false' or searx_debug_env == '0': + searx_debug = False +else: + searx_debug = settings.get('general', {}).get('debug') + +if searx_debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.WARNING) diff --git a/searx/webapp.py b/searx/webapp.py index 6c2b98c9c..6a1bb4efb 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -51,7 +51,7 @@ from flask import ( ) from flask_babel import Babel, gettext, format_date, format_decimal from flask.json import jsonify -from searx import settings, searx_dir +from searx import settings, searx_dir, searx_debug from searx.engines import ( categories, engines, get_engines_stats, engine_shortcuts ) @@ -743,8 +743,8 @@ def page_not_found(e): def run(): app.run( - debug=settings['general']['debug'], - use_debugger=settings['general']['debug'], + debug=searx_debug, + use_debugger=searx_debug, port=settings['server']['port'], host=settings['server']['bind_address'], threaded=True