summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--searx/__init__.py12
-rw-r--r--searx/engines/__init__.py11
-rw-r--r--searx/https_rewrite.py7
-rw-r--r--searx/search.py7
-rw-r--r--searx/templates/default/result_templates/map.html2
-rw-r--r--searx/templates/default/result_templates/torrent.html2
-rw-r--r--searx/webapp.py5
7 files changed, 35 insertions, 11 deletions
diff --git a/searx/__init__.py b/searx/__init__.py
index 46685817a..110f46af8 100644
--- a/searx/__init__.py
+++ b/searx/__init__.py
@@ -15,9 +15,9 @@ along with searx. If not, see < http://www.gnu.org/licenses/ >.
(C) 2013- by Adam Tauber, <asciimoo@gmail.com>
'''
+import logging
from os import environ
from os.path import realpath, dirname, join, abspath
-from searx.https_rewrite import load_https_rules
try:
from yaml import load
except:
@@ -45,7 +45,17 @@ else:
with open(settings_path) as settings_yaml:
settings = load(settings_yaml)
+if settings.get('server', {}).get('debug'):
+ logging.basicConfig(level=logging.DEBUG)
+else:
+ logging.basicConfig(level=logging.WARNING)
+
+logger = logging.getLogger('searx')
+
# load https rules only if https rewrite is enabled
if settings.get('server', {}).get('https_rewrite'):
# loade https rules
+ from searx.https_rewrite import load_https_rules
load_https_rules(https_rewrite_path)
+
+logger.info('Initialisation done')
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 9bc5cdfd4..643b107a5 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -22,6 +22,10 @@ from imp import load_source
from flask.ext.babel import gettext
from operator import itemgetter
from searx import settings
+from searx import logger
+
+
+logger = logger.getChild('engines')
engine_dir = dirname(realpath(__file__))
@@ -81,7 +85,7 @@ def load_engine(engine_data):
if engine_attr.startswith('_'):
continue
if getattr(engine, engine_attr) is None:
- print('[E] Engine config error: Missing attribute "{0}.{1}"'
+ logger.error('Missing engine config attribute: "{0}.{1}"'
.format(engine.name, engine_attr))
sys.exit(1)
@@ -100,9 +104,8 @@ def load_engine(engine_data):
categories['general'].append(engine)
if engine.shortcut:
- # TODO check duplications
if engine.shortcut in engine_shortcuts:
- print('[E] Engine config error: ambigious shortcut: {0}'
+ logger.error('Engine config error: ambigious shortcut: {0}'
.format(engine.shortcut))
sys.exit(1)
engine_shortcuts[engine.shortcut] = engine.name
@@ -199,7 +202,7 @@ def get_engines_stats():
if 'engines' not in settings or not settings['engines']:
- print '[E] Error no engines found. Edit your settings.yml'
+ logger.error('No engines found. Edit your settings.yml')
exit(2)
for engine_data in settings['engines']:
diff --git a/searx/https_rewrite.py b/searx/https_rewrite.py
index d873b406d..71aec1c9b 100644
--- a/searx/https_rewrite.py
+++ b/searx/https_rewrite.py
@@ -20,8 +20,11 @@ from urlparse import urlparse
from lxml import etree
from os import listdir
from os.path import isfile, isdir, join
+from searx import logger
+logger = logger.getChild("https_rewrite")
+
# https://gitweb.torproject.org/\
# pde/https-everywhere.git/tree/4.0:/src/chrome/content/rules
@@ -131,7 +134,7 @@ def load_single_https_ruleset(filepath):
def load_https_rules(rules_path):
# check if directory exists
if not isdir(rules_path):
- print("[E] directory not found: '" + rules_path + "'")
+ logger.error("directory not found: '" + rules_path + "'")
return
# search all xml files which are stored in the https rule directory
@@ -151,7 +154,7 @@ def load_https_rules(rules_path):
# append ruleset
https_rules.append(ruleset)
- print(' * {n} https-rules loaded'.format(n=len(https_rules)))
+ logger.info('{n} rules loaded'.format(n=len(https_rules)))
def https_url_rewrite(result):
diff --git a/searx/search.py b/searx/search.py
index fbbf3fe41..a31d8eace 100644
--- a/searx/search.py
+++ b/searx/search.py
@@ -29,8 +29,11 @@ from searx.engines import (
from searx.languages import language_codes
from searx.utils import gen_useragent
from searx.query import Query
+from searx import logger
+logger = logger.getChild('search')
+
number_of_searches = 0
@@ -42,7 +45,7 @@ def search_request_wrapper(fn, url, engine_name, **kwargs):
engines[engine_name].stats['errors'] += 1
# print engine name and specific error message
- print('[E] Error with engine "{0}":\n\t{1}'.format(
+ logger.warning('engine crash: {0}\n\t{1}'.format(
engine_name, str(e)))
return
@@ -66,7 +69,7 @@ def threaded_requests(requests):
remaining_time = max(0.0, timeout_limit - (time() - search_start))
th.join(remaining_time)
if th.isAlive():
- print('engine timeout: {0}'.format(th._engine_name))
+ logger.warning('engine timeout: {0}'.format(th._engine_name))
# get default reqest parameter
diff --git a/searx/templates/default/result_templates/map.html b/searx/templates/default/result_templates/map.html
index b3669f895..d37c2f374 100644
--- a/searx/templates/default/result_templates/map.html
+++ b/searx/templates/default/result_templates/map.html
@@ -1,7 +1,7 @@
<div class="result {{ result.class }}">
{% if "icon_"~result.engine~".ico" in favicons %}
- <img width="14" height="14" class="favicon" src="{{ url_for('static', filename='img/icons/icon_'+result.engine+'.ico) }}" alt="{{result.engine}}" />
+ <img width="14" height="14" class="favicon" src="{{ url_for('static', filename='img/icons/icon_'+result.engine+'.ico') }}" alt="{{result.engine}}" />
{% endif %}
<div>
diff --git a/searx/templates/default/result_templates/torrent.html b/searx/templates/default/result_templates/torrent.html
index fb8988680..4c79a0a39 100644
--- a/searx/templates/default/result_templates/torrent.html
+++ b/searx/templates/default/result_templates/torrent.html
@@ -1,6 +1,6 @@
<div class="result torrent_result">
{% if "icon_"~result.engine~".ico" in favicons %}
- <img width="14" height="14" class="favicon" src="{{ url_for('static', filename='img/icons/icon_'+result.engine+'.ico) }}" alt="{{result.engine}}" />
+ <img width="14" height="14" class="favicon" src="{{ url_for('static', filename='img/icons/icon_'+result.engine+'.ico') }}" alt="{{result.engine}}" />
{% endif %}
<h3 class="result_title"><a href="{{ result.url }}">{{ result.title|safe }}</a></h3>
<p class="url">{{ result.pretty_url }}</p>
diff --git a/searx/webapp.py b/searx/webapp.py
index 6ee9af745..24d329858 100644
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -47,8 +47,11 @@ from searx.https_rewrite import https_url_rewrite
from searx.search import Search
from searx.query import Query
from searx.autocomplete import backends as autocomplete_backends
+from searx import logger
+logger = logger.getChild('webapp')
+
static_path, templates_path, themes =\
get_themes(settings['themes_path']
if settings.get('themes_path')
@@ -68,6 +71,8 @@ app = Flask(
app.secret_key = settings['server']['secret_key']
+app.logger.addHandler(logger)
+
babel = Babel(app)
global_favicons = []