on master help sign in
[enh] using the logger
commit299a80a1eb2eecb80f5c50da261a9eab1900b572 authorAdam Tauber <asciimoo@gmail.com> dateFri 9 Jan 2015, 04:13 (12 years ago) parent425a576
4 files changed+22−8
searx/engines/__init__.py+7−4 searx/https_rewrite.py+5−2 searx/search.py+5−2 searx/webapp.py+5
searx/engines/__init__.py+7−4
@@ -22,6 +22,10 @@ from imp import load_source
2222from flask.ext.babel import gettext
2323from operator import itemgetter
2424from searx import settings
25+from searx import logger
26+
27+
28+logger = logger.getChild('engines')
2529
2630engine_dir = dirname(realpath(__file__))
2731
@@ -81,7 +85,7 @@ def load_engine(engine_data):
8185 if engine_attr.startswith('_'):
8286 continue
8387 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}"'
8589 .format(engine.name, engine_attr))
8690 sys.exit(1)
8791
@@ -100,9 +104,8 @@ def load_engine(engine_data):
100104 categories['general'].append(engine)
101105
102106 if engine.shortcut:
103− # TODO check duplications
104107 if engine.shortcut in engine_shortcuts:
105− print('[E] Engine config error: ambigious shortcut: {0}'
108+ logger.error('Engine config error: ambigious shortcut: {0}'
106109 .format(engine.shortcut))
107110 sys.exit(1)
108111 engine_shortcuts[engine.shortcut] = engine.name
@@ -199,7 +202,7 @@ def get_engines_stats():
199202
200203
201204if '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')
203206 exit(2)
204207
205208for engine_data in settings['engines']:
searx/https_rewrite.py+5−2
@@ -20,8 +20,11 @@ from urlparse import urlparse
2020from lxml import etree
2121from os import listdir
2222from os.path import isfile, isdir, join
23+from searx import logger
2324
2425
26+logger = logger.getChild("https_rewrite")
27+
2528# https://gitweb.torproject.org/\
2629# pde/https-everywhere.git/tree/4.0:/src/chrome/content/rules
2730
@@ -131,7 +134,7 @@ def load_single_https_ruleset(filepath):
131134def load_https_rules(rules_path):
132135 # check if directory exists
133136 if not isdir(rules_path):
134− print("[E] directory not found: '" + rules_path + "'")
137+ logger.error("directory not found: '" + rules_path + "'")
135138 return
136139
137140 # search all xml files which are stored in the https rule directory
@@ -151,7 +154,7 @@ def load_https_rules(rules_path):
151154 # append ruleset
152155 https_rules.append(ruleset)
153156
154− print(' * {n} https-rules loaded'.format(n=len(https_rules)))
157+ logger.info('{n} rules loaded'.format(n=len(https_rules)))
155158
156159
157160def https_url_rewrite(result):
searx/search.py+5−2
@@ -29,8 +29,11 @@ from searx.engines import (
2929from searx.languages import language_codes
3030from searx.utils import gen_useragent
3131from searx.query import Query
32+from searx import logger
3233
3334
35+logger = logger.getChild('search')
36+
3437number_of_searches = 0
3538
3639
@@ -42,7 +45,7 @@ def search_request_wrapper(fn, url, engine_name, **kwargs):
4245 engines[engine_name].stats['errors'] += 1
4346
4447 # 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(
4649 engine_name, str(e)))
4750 return
4851
@@ -66,7 +69,7 @@ def threaded_requests(requests):
6669 remaining_time = max(0.0, timeout_limit - (time() - search_start))
6770 th.join(remaining_time)
6871 if th.isAlive():
69− print('engine timeout: {0}'.format(th._engine_name))
72+ logger.warning('engine timeout: {0}'.format(th._engine_name))
7073
7174
7275# get default reqest parameter
searx/webapp.py+5
@@ -47,8 +47,11 @@ from searx.https_rewrite import https_url_rewrite
4747from searx.search import Search
4848from searx.query import Query
4949from searx.autocomplete import backends as autocomplete_backends
50+from searx import logger
5051
5152
53+logger = logger.getChild('webapp')
54+
5255static_path, templates_path, themes =\
5356 get_themes(settings['themes_path']
5457 if settings.get('themes_path')
@@ -68,6 +71,8 @@ app = Flask(
6871
6972app.secret_key = settings['server']['secret_key']
7073
74+app.logger.addHandler(logger)
75+
7176babel = Babel(app)
7277
7378global_favicons = []