on master help sign in
[enh] using the logger
299a80aAdam Tauber
searx/engines/__init__.py+7−4
@@ -22,6 +22,10 @@ from imp import load_source
22from flask.ext.babel import gettext
22from flask.ext.babel import gettext
23from operator import itemgetter
23from operator import itemgetter
24from searx import settings
24from searx import settings
25+from searx import logger
26+
27+
28+logger = logger.getChild('engines')
25
29
26engine_dir = dirname(realpath(__file__))
30engine_dir = dirname(realpath(__file__))
27
31
@@ -81,7 +85,7 @@ def load_engine(engine_data):
81 if engine_attr.startswith('_'):
85 if engine_attr.startswith('_'):
82 continue
86 continue
83 if getattr(engine, engine_attr) is None:
87 if getattr(engine, engine_attr) is None:
84− print('[E] Engine config error: Missing attribute "{0}.{1}"'
88+ logger.error('Missing engine config attribute: "{0}.{1}"'
85 .format(engine.name, engine_attr))
89 .format(engine.name, engine_attr))
86 sys.exit(1)
90 sys.exit(1)
87
91
@@ -100,9 +104,8 @@ def load_engine(engine_data):
100 categories['general'].append(engine)
104 categories['general'].append(engine)
101
105
102 if engine.shortcut:
106 if engine.shortcut:
103− # TODO check duplications
104 if engine.shortcut in engine_shortcuts:
107 if engine.shortcut in engine_shortcuts:
105− print('[E] Engine config error: ambigious shortcut: {0}'
108+ logger.error('Engine config error: ambigious shortcut: {0}'
106 .format(engine.shortcut))
109 .format(engine.shortcut))
107 sys.exit(1)
110 sys.exit(1)
108 engine_shortcuts[engine.shortcut] = engine.name
111 engine_shortcuts[engine.shortcut] = engine.name
@@ -199,7 +202,7 @@ def get_engines_stats():
199
202
200
203
201if 'engines' not in settings or not settings['engines']:
204if 'engines' not in settings or not settings['engines']:
202− print '[E] Error no engines found. Edit your settings.yml'
205+ logger.error('No engines found. Edit your settings.yml')
203 exit(2)
206 exit(2)
204
207
205for engine_data in settings['engines']:
208for engine_data in settings['engines']:
searx/https_rewrite.py+5−2
@@ -20,8 +20,11 @@ from urlparse import urlparse
20from lxml import etree
20from lxml import etree
21from os import listdir
21from os import listdir
22from os.path import isfile, isdir, join
22from os.path import isfile, isdir, join
23+from searx import logger
23
24
24
25
26+logger = logger.getChild("https_rewrite")
27+
25# https://gitweb.torproject.org/\
28# https://gitweb.torproject.org/\
26# pde/https-everywhere.git/tree/4.0:/src/chrome/content/rules
29# pde/https-everywhere.git/tree/4.0:/src/chrome/content/rules
27
30
@@ -131,7 +134,7 @@ def load_single_https_ruleset(filepath):
131def load_https_rules(rules_path):
134def load_https_rules(rules_path):
132 # check if directory exists
135 # check if directory exists
133 if not isdir(rules_path):
136 if not isdir(rules_path):
134− print("[E] directory not found: '" + rules_path + "'")
137+ logger.error("directory not found: '" + rules_path + "'")
135 return
138 return
136
139
137 # search all xml files which are stored in the https rule directory
140 # search all xml files which are stored in the https rule directory
@@ -151,7 +154,7 @@ def load_https_rules(rules_path):
151 # append ruleset
154 # append ruleset
152 https_rules.append(ruleset)
155 https_rules.append(ruleset)
153
156
154− print(' * {n} https-rules loaded'.format(n=len(https_rules)))
157+ logger.info('{n} rules loaded'.format(n=len(https_rules)))
155
158
156
159
157def https_url_rewrite(result):
160def https_url_rewrite(result):
searx/search.py+5−2
@@ -29,8 +29,11 @@ from searx.engines import (
29from searx.languages import language_codes
29from searx.languages import language_codes
30from searx.utils import gen_useragent
30from searx.utils import gen_useragent
31from searx.query import Query
31from searx.query import Query
32+from searx import logger
32
33
33
34
35+logger = logger.getChild('search')
36+
34number_of_searches = 0
37number_of_searches = 0
35
38
36
39
@@ -42,7 +45,7 @@ def search_request_wrapper(fn, url, engine_name, **kwargs):
42 engines[engine_name].stats['errors'] += 1
45 engines[engine_name].stats['errors'] += 1
43
46
44 # print engine name and specific error message
47 # print engine name and specific error message
45− print('[E] Error with engine "{0}":\n\t{1}'.format(
48+ logger.warning('engine crash: {0}\n\t{1}'.format(
46 engine_name, str(e)))
49 engine_name, str(e)))
47 return
50 return
48
51
@@ -66,7 +69,7 @@ def threaded_requests(requests):
66 remaining_time = max(0.0, timeout_limit - (time() - search_start))
69 remaining_time = max(0.0, timeout_limit - (time() - search_start))
67 th.join(remaining_time)
70 th.join(remaining_time)
68 if th.isAlive():
71 if th.isAlive():
69− print('engine timeout: {0}'.format(th._engine_name))
72+ logger.warning('engine timeout: {0}'.format(th._engine_name))
70
73
71
74
72# get default reqest parameter
75# get default reqest parameter
searx/webapp.py+5
@@ -47,8 +47,11 @@ from searx.https_rewrite import https_url_rewrite
47from searx.search import Search
47from searx.search import Search
48from searx.query import Query
48from searx.query import Query
49from searx.autocomplete import backends as autocomplete_backends
49from searx.autocomplete import backends as autocomplete_backends
50+from searx import logger
50
51
51
52
53+logger = logger.getChild('webapp')
54+
52static_path, templates_path, themes =\
55static_path, templates_path, themes =\
53 get_themes(settings['themes_path']
56 get_themes(settings['themes_path']
54 if settings.get('themes_path')
57 if settings.get('themes_path')
@@ -68,6 +71,8 @@ app = Flask(
68
71
69app.secret_key = settings['server']['secret_key']
72app.secret_key = settings['server']['secret_key']
70
73
74+app.logger.addHandler(logger)
75+
71babel = Babel(app)
76babel = Babel(app)
72
77
73global_favicons = []
78global_favicons = []