summaryrefslogtreecommitdiff
path: root/searx/search/processors
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-09-06 19:46:08 +0200
committerAlexandre Flament <alex@al-f.net>2021-09-10 21:49:34 +0200
commitb513917ef94d2f18e6db3228363f8089ce1ba08a (patch)
tree7df26e78c31a6785f972d8c68e500098176c9a8a /searx/search/processors
parent76e0f6807ccddb12ca9efe3b2343735d6e1777d4 (diff)
[mod] searx.metrics & searx.search: use the engine loggers
metrics & processors use the engine logger
Diffstat (limited to 'searx/search/processors')
-rw-r--r--searx/search/processors/__init__.py2
-rw-r--r--searx/search/processors/abstract.py15
-rw-r--r--searx/search/processors/offline.py6
-rw-r--r--searx/search/processors/online.py36
4 files changed, 31 insertions, 28 deletions
diff --git a/searx/search/processors/__init__.py b/searx/search/processors/__init__.py
index b3d121f0..8108f8df 100644
--- a/searx/search/processors/__init__.py
+++ b/searx/search/processors/__init__.py
@@ -65,6 +65,6 @@ def initialize(engine_list):
processor = get_processor(engine, engine_name)
initialize_processor(processor)
if processor is None:
- logger.error('Error get processor for engine %s', engine_name)
+ engine.logger.error('Error get processor for engine %s', engine_name)
else:
PROCESSORS[engine_name] = processor
diff --git a/searx/search/processors/abstract.py b/searx/search/processors/abstract.py
index c8d81c02..b5fa063f 100644
--- a/searx/search/processors/abstract.py
+++ b/searx/search/processors/abstract.py
@@ -9,8 +9,8 @@ import threading
from abc import abstractmethod, ABC
from timeit import default_timer
-from searx import logger
-from searx.engines import settings
+from searx import settings, logger
+from searx.engines import engines
from searx.network import get_time_for_thread, get_network
from searx.metrics import histogram_observe, counter_inc, count_exception, count_error
from searx.exceptions import SearxEngineAccessDeniedException, SearxEngineResponseException
@@ -43,7 +43,7 @@ class SuspendedStatus:
self.continuous_errors * settings['search']['ban_time_on_fail'])
self.suspend_end_time = default_timer() + suspended_time
self.suspend_reason = suspend_reason
- logger.debug('Suspend engine for %i seconds', suspended_time)
+ logger.debug('Suspend for %i seconds', suspended_time)
def resume(self):
with self.lock:
@@ -56,11 +56,12 @@ class SuspendedStatus:
class EngineProcessor(ABC):
"""Base classes used for all types of reqest processores."""
- __slots__ = 'engine', 'engine_name', 'lock', 'suspended_status'
+ __slots__ = 'engine', 'engine_name', 'lock', 'suspended_status', 'logger'
def __init__(self, engine, engine_name):
self.engine = engine
self.engine_name = engine_name
+ self.logger = engines[engine_name].logger
key = get_network(self.engine_name)
key = id(key) if key else self.engine_name
self.suspended_status = SUSPENDED_STATUS.setdefault(key, SuspendedStatus())
@@ -69,11 +70,11 @@ class EngineProcessor(ABC):
try:
self.engine.init(get_engine_from_settings(self.engine_name))
except SearxEngineResponseException as exc:
- logger.warn('%s engine: Fail to initialize // %s', self.engine_name, exc)
+ self.logger.warn('Fail to initialize // %s', exc)
except Exception: # pylint: disable=broad-except
- logger.exception('%s engine: Fail to initialize', self.engine_name)
+ self.logger.exception('Fail to initialize')
else:
- logger.debug('%s engine: Initialized', self.engine_name)
+ self.logger.debug('Initialized')
@property
def has_initialize_function(self):
diff --git a/searx/search/processors/offline.py b/searx/search/processors/offline.py
index f40626f3..ec7a4a36 100644
--- a/searx/search/processors/offline.py
+++ b/searx/search/processors/offline.py
@@ -5,10 +5,8 @@
"""
-from searx import logger
from .abstract import EngineProcessor
-logger = logger.getChild('searx.search.processor.offline')
class OfflineProcessor(EngineProcessor):
"""Processor class used by ``offline`` engines"""
@@ -24,7 +22,7 @@ class OfflineProcessor(EngineProcessor):
self.extend_container(result_container, start_time, search_results)
except ValueError as e:
# do not record the error
- logger.exception('engine {0} : invalid input : {1}'.format(self.engine_name, e))
+ self.logger.exception('engine {0} : invalid input : {1}'.format(self.engine_name, e))
except Exception as e: # pylint: disable=broad-except
self.handle_exception(result_container, e)
- logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
+ self.logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
diff --git a/searx/search/processors/online.py b/searx/search/processors/online.py
index 48a514e8..c4ee58e1 100644
--- a/searx/search/processors/online.py
+++ b/searx/search/processors/online.py
@@ -10,7 +10,6 @@ import asyncio
import httpx
import searx.network
-from searx import logger
from searx.utils import gen_useragent
from searx.exceptions import (
SearxEngineAccessDeniedException,
@@ -20,7 +19,6 @@ from searx.exceptions import (
from searx.metrics.error_recorder import count_error
from .abstract import EngineProcessor
-logger = logger.getChild('searx.search.processor.online')
def default_request_params():
"""Default request parameters for ``online`` engines."""
@@ -146,31 +144,37 @@ class OnlineProcessor(EngineProcessor):
except (httpx.TimeoutException, asyncio.TimeoutError) as e:
# requests timeout (connect or read)
self.handle_exception(result_container, e, suspend=True)
- logger.error("engine {0} : HTTP requests timeout"
- "(search duration : {1} s, timeout: {2} s) : {3}"
- .format(self.engine_name, default_timer() - start_time,
- timeout_limit,
- e.__class__.__name__))
+ self.logger.error(
+ "HTTP requests timeout (search duration : {0} s, timeout: {1} s) : {2}"
+ .format(
+ default_timer() - start_time,
+ timeout_limit,
+ e.__class__.__name__
+ )
+ )
except (httpx.HTTPError, httpx.StreamError) as e:
# other requests exception
self.handle_exception(result_container, e, suspend=True)
- logger.exception("engine {0} : requests exception"
- "(search duration : {1} s, timeout: {2} s) : {3}"
- .format(self.engine_name, default_timer() - start_time,
- timeout_limit,
- e))
+ self.logger.exception(
+ "requests exception (search duration : {0} s, timeout: {1} s) : {2}"
+ .format(
+ default_timer() - start_time,
+ timeout_limit,
+ e
+ )
+ )
except SearxEngineCaptchaException as e:
self.handle_exception(result_container, e, suspend=True)
- logger.exception('engine {0} : CAPTCHA'.format(self.engine_name))
+ self.logger.exception('CAPTCHA')
except SearxEngineTooManyRequestsException as e:
self.handle_exception(result_container, e, suspend=True)
- logger.exception('engine {0} : Too many requests'.format(self.engine_name))
+ self.logger.exception('Too many requests')
except SearxEngineAccessDeniedException as e:
self.handle_exception(result_container, e, suspend=True)
- logger.exception('engine {0} : Searx is blocked'.format(self.engine_name))
+ self.logger.exception('Searx is blocked')
except Exception as e: # pylint: disable=broad-except
self.handle_exception(result_container, e)
- logger.exception('engine {0} : exception : {1}'.format(self.engine_name, e))
+ self.logger.exception('exception : {0}'.format(e))
def get_default_tests(self):
tests = {}