From 7b235a1c36b09cfe2c6b4c97c3b6dad77e51d5ae Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 6 Sep 2021 17:47:28 +0200 Subject: [PATCH 1/2] [mod] one logger per engine Suggested-by: @dalf in https://github.com/searxng/searxng/issues/98#issuecomment-849013518 Signed-off-by: Markus Heiser --- manage | 3 ++- searx/engines/__init__.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/manage b/manage index 6f6f1a4fe..b20442260 100755 --- a/manage +++ b/manage @@ -37,7 +37,7 @@ PYLINT_SEARX_DISABLE_OPTION="\ I,C,R,\ W0105,W0212,W0511,W0603,W0613,W0621,W0702,W0703,W1401,\ E1136" -PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES="supported_languages,language_aliases" +PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES="supported_languages,language_aliases,logger" PYLINT_OPTIONS="-m pylint -j 0 --rcfile .pylintrc" help() { @@ -588,6 +588,7 @@ test.pylint() { ( set -e build_msg TEST "[pylint] \$PYLINT_FILES" pyenv.cmd python ${PYLINT_OPTIONS} ${PYLINT_VERBOSE} \ + --additional-builtins="${PYLINT_ADDITIONAL_BUILTINS_FOR_ENGINES}" \ "${PYLINT_FILES[@]}" build_msg TEST "[pylint] searx/engines" diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py index d7defe0b4..1ac675c4c 100644 --- a/searx/engines/__init__.py +++ b/searx/engines/__init__.py @@ -111,6 +111,7 @@ def load_engine(engine_data): if is_missing_required_attributes(engine): return None + engine.logger = logger.getChild(engine_name) return engine From aecfb2300d2515ee5bb28058d4fb11b8fe5c3f04 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Mon, 6 Sep 2021 18:05:46 +0200 Subject: [PATCH 2/2] [mod] one logger per engine - drop obsolete logger.getChild Remove the no longer needed `logger = logger.getChild(...)` from engines. Signed-off-by: Markus Heiser --- searx/engines/apkmirror.py | 3 --- searx/engines/artic.py | 3 --- searx/engines/bing.py | 3 --- searx/engines/core.py | 5 ----- searx/engines/duckduckgo_definitions.py | 3 --- searx/engines/flickr_noapi.py | 3 --- searx/engines/genius.py | 3 --- searx/engines/gigablast.py | 1 - searx/engines/google.py | 3 --- searx/engines/google_images.py | 3 --- searx/engines/google_news.py | 3 --- searx/engines/google_scholar.py | 3 --- searx/engines/google_videos.py | 3 --- searx/engines/solidtorrents.py | 3 --- searx/engines/soundcloud.py | 1 - searx/engines/springer.py | 3 --- searx/engines/sqlite.py | 5 ----- searx/engines/unsplash.py | 3 --- searx/engines/wikidata.py | 3 --- searx/engines/wordnik.py | 3 --- searx/engines/xpath.py | 3 --- searx/engines/yahoo_news.py | 3 --- 22 files changed, 66 deletions(-) diff --git a/searx/engines/apkmirror.py b/searx/engines/apkmirror.py index 855d19739..36e838227 100644 --- a/searx/engines/apkmirror.py +++ b/searx/engines/apkmirror.py @@ -8,15 +8,12 @@ from urllib.parse import urlencode from lxml import html -from searx import logger from searx.utils import ( eval_xpath_list, eval_xpath_getindex, extract_text, ) -logger = logger.getChild('APKMirror engine') - about = { "website": 'https://www.apkmirror.com', "wikidata_id": None, diff --git a/searx/engines/artic.py b/searx/engines/artic.py index 44af4ebd5..85d355ed3 100644 --- a/searx/engines/artic.py +++ b/searx/engines/artic.py @@ -13,9 +13,6 @@ Explore thousands of artworks from The Art Institute of Chicago. from json import loads from urllib.parse import urlencode -from searx import logger -logger = logger.getChild('APKMirror engine') - about = { "website": 'https://www.artic.edu', "wikidata_id": 'Q239303', diff --git a/searx/engines/bing.py b/searx/engines/bing.py index f849cef92..9cac3e926 100644 --- a/searx/engines/bing.py +++ b/searx/engines/bing.py @@ -6,11 +6,8 @@ import re from urllib.parse import urlencode from lxml import html -from searx import logger from searx.utils import eval_xpath, extract_text, match_language -logger = logger.getChild('bing engine') - # about about = { "website": 'https://www.bing.com', diff --git a/searx/engines/core.py b/searx/engines/core.py index 0d9724695..5e87400bd 100644 --- a/searx/engines/core.py +++ b/searx/engines/core.py @@ -9,11 +9,8 @@ from json import loads from datetime import datetime from urllib.parse import urlencode -from searx import logger from searx.exceptions import SearxEngineAPIException -logger = logger.getChild('CORE engine') - about = { "website": 'https://core.ac.uk', "wikidata_id": 'Q22661180', @@ -29,8 +26,6 @@ nb_per_page = 10 api_key = 'unset' -logger = logger.getChild('CORE engine') - base_url = 'https://core.ac.uk:443/api-v2/search/' search_string = '{query}?page={page}&pageSize={nb_per_page}&apiKey={apikey}' diff --git a/searx/engines/duckduckgo_definitions.py b/searx/engines/duckduckgo_definitions.py index a9098de65..e35b55f74 100644 --- a/searx/engines/duckduckgo_definitions.py +++ b/searx/engines/duckduckgo_definitions.py @@ -9,15 +9,12 @@ import json from urllib.parse import urlencode, urlparse, urljoin from lxml import html -from searx import logger from searx.data import WIKIDATA_UNITS from searx.engines.duckduckgo import language_aliases from searx.engines.duckduckgo import _fetch_supported_languages, supported_languages_url # NOQA # pylint: disable=unused-import from searx.utils import extract_text, html_to_text, match_language, get_string_replaces_function from searx.external_urls import get_external_url, get_earth_coordinates_url, area_to_osm_zoom -logger = logger.getChild('duckduckgo_definitions') - # about about = { "website": 'https://duckduckgo.com/', diff --git a/searx/engines/flickr_noapi.py b/searx/engines/flickr_noapi.py index a07aad51e..1d670ee50 100644 --- a/searx/engines/flickr_noapi.py +++ b/searx/engines/flickr_noapi.py @@ -7,11 +7,8 @@ from json import loads from time import time import re from urllib.parse import urlencode -from searx.engines import logger from searx.utils import ecma_unescape, html_to_text -logger = logger.getChild('flickr-noapi') - # about about = { "website": 'https://www.flickr.com', diff --git a/searx/engines/genius.py b/searx/engines/genius.py index 9d701a8de..49fda0053 100644 --- a/searx/engines/genius.py +++ b/searx/engines/genius.py @@ -9,9 +9,6 @@ from json import loads from urllib.parse import urlencode from datetime import datetime -from searx import logger -logger = logger.getChild('genius engine') - # about about = { "website": 'https://genius.com/', diff --git a/searx/engines/gigablast.py b/searx/engines/gigablast.py index d1c2639af..376467d9b 100644 --- a/searx/engines/gigablast.py +++ b/searx/engines/gigablast.py @@ -8,7 +8,6 @@ import re from json import loads from urllib.parse import urlencode -# from searx import logger from searx.network import get # about diff --git a/searx/engines/google.py b/searx/engines/google.py index e1caabb12..d1f564d99 100644 --- a/searx/engines/google.py +++ b/searx/engines/google.py @@ -29,12 +29,9 @@ The google WEB engine itself has a special setup option: from urllib.parse import urlencode from lxml import html -from searx import logger from searx.utils import match_language, extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex from searx.exceptions import SearxEngineCaptchaException -logger = logger.getChild('google engine') - # about about = { "website": 'https://www.google.com', diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py index f4fbbaa42..bd13144b2 100644 --- a/searx/engines/google_images.py +++ b/searx/engines/google_images.py @@ -16,7 +16,6 @@ from urllib.parse import urlencode, unquote from lxml import html -from searx import logger from searx.utils import ( eval_xpath, eval_xpath_list, @@ -37,8 +36,6 @@ from searx.engines.google import ( ) # pylint: enable=unused-import -logger = logger.getChild('google images') - # about about = { "website": 'https://images.google.com', diff --git a/searx/engines/google_news.py b/searx/engines/google_news.py index e6d50855e..0dd0c7b94 100644 --- a/searx/engines/google_news.py +++ b/searx/engines/google_news.py @@ -20,7 +20,6 @@ from urllib.parse import urlencode from base64 import b64decode from lxml import html -from searx import logger from searx.utils import ( eval_xpath, eval_xpath_list, @@ -50,8 +49,6 @@ about = { "results": 'HTML', } -logger = logger.getChild('google news') - # compared to other google engines google-news has a different time range # support. The time range is included in the search term. time_range_dict = { diff --git a/searx/engines/google_scholar.py b/searx/engines/google_scholar.py index 8442a7bfa..5c7a0d9e9 100644 --- a/searx/engines/google_scholar.py +++ b/searx/engines/google_scholar.py @@ -14,7 +14,6 @@ Definitions`_. from urllib.parse import urlencode from datetime import datetime from lxml import html -from searx import logger from searx.utils import ( eval_xpath, @@ -53,8 +52,6 @@ use_locale_domain = True time_range_support = True safesearch = False -logger = logger.getChild('google scholar') - def time_range_url(params): """Returns a URL query component for a google-Scholar time range based on ``params['time_range']``. Google-Scholar does only support ranges in years. diff --git a/searx/engines/google_videos.py b/searx/engines/google_videos.py index 3990d5b32..f75b9f5d5 100644 --- a/searx/engines/google_videos.py +++ b/searx/engines/google_videos.py @@ -20,7 +20,6 @@ import re from urllib.parse import urlencode from lxml import html -from searx import logger from searx.utils import ( eval_xpath, eval_xpath_list, @@ -59,8 +58,6 @@ about = { "results": 'HTML', } -logger = logger.getChild('google video') - # engine dependent config categories = ['videos'] diff --git a/searx/engines/solidtorrents.py b/searx/engines/solidtorrents.py index 4ed6167d0..57bf675cd 100644 --- a/searx/engines/solidtorrents.py +++ b/searx/engines/solidtorrents.py @@ -8,9 +8,6 @@ from json import loads from urllib.parse import urlencode -from searx import logger - -logger = logger.getChild('solidtor engine') about = { "website": 'https://www.solidtorrents.net/', diff --git a/searx/engines/soundcloud.py b/searx/engines/soundcloud.py index a6f923855..d5bfc0f6f 100644 --- a/searx/engines/soundcloud.py +++ b/searx/engines/soundcloud.py @@ -8,7 +8,6 @@ from json import loads from lxml import html from dateutil import parser from urllib.parse import quote_plus, urlencode -from searx import logger from searx.network import get as http_get # about diff --git a/searx/engines/springer.py b/searx/engines/springer.py index 77a82016b..4288d0b4c 100644 --- a/searx/engines/springer.py +++ b/searx/engines/springer.py @@ -10,11 +10,8 @@ from datetime import datetime from json import loads from urllib.parse import urlencode -from searx import logger from searx.exceptions import SearxEngineAPIException -logger = logger.getChild('Springer Nature engine') - about = { "website": 'https://www.springernature.com/', "wikidata_id": 'Q21096327', diff --git a/searx/engines/sqlite.py b/searx/engines/sqlite.py index 84db74d62..9a639ff9a 100644 --- a/searx/engines/sqlite.py +++ b/searx/engines/sqlite.py @@ -9,11 +9,6 @@ import sqlite3 import contextlib -from searx import logger - - -logger = logger.getChild('SQLite engine') - engine_type = 'offline' database = "" query_str = "" diff --git a/searx/engines/unsplash.py b/searx/engines/unsplash.py index 834bc917c..dcca18ee6 100644 --- a/searx/engines/unsplash.py +++ b/searx/engines/unsplash.py @@ -8,9 +8,6 @@ from urllib.parse import urlencode, urlparse, urlunparse, parse_qsl from json import loads -from searx import logger - -logger = logger.getChild('unsplash engine') # about about = { "website": 'https://unsplash.com', diff --git a/searx/engines/wikidata.py b/searx/engines/wikidata.py index ddcce9085..f0dfc7595 100644 --- a/searx/engines/wikidata.py +++ b/searx/engines/wikidata.py @@ -10,15 +10,12 @@ from json import loads from dateutil.parser import isoparse from babel.dates import format_datetime, format_date, format_time, get_datetime_format -from searx import logger from searx.data import WIKIDATA_UNITS from searx.network import post, get from searx.utils import match_language, searx_useragent, get_string_replaces_function from searx.external_urls import get_external_url, get_earth_coordinates_url, area_to_osm_zoom from searx.engines.wikipedia import _fetch_supported_languages, supported_languages_url # NOQA # pylint: disable=unused-import -logger = logger.getChild('wikidata') - # about about = { "website": 'https://wikidata.org/', diff --git a/searx/engines/wordnik.py b/searx/engines/wordnik.py index 4bfeb4070..0c3785cfb 100644 --- a/searx/engines/wordnik.py +++ b/searx/engines/wordnik.py @@ -4,12 +4,9 @@ """ from lxml.html import fromstring -from searx import logger from searx.utils import extract_text from searx.network import raise_for_httperror -logger = logger.getChild('Wordnik engine') - # about about = { "website": 'https://www.wordnik.com', diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py index 0f88fb29a..3a8d32a6a 100644 --- a/searx/engines/xpath.py +++ b/searx/engines/xpath.py @@ -23,9 +23,6 @@ from urllib.parse import urlencode from lxml import html from searx.utils import extract_text, extract_url, eval_xpath, eval_xpath_list -from searx import logger - -logger = logger.getChild('XPath engine') search_url = None """ diff --git a/searx/engines/yahoo_news.py b/searx/engines/yahoo_news.py index 98d8bc9f1..750373ffb 100644 --- a/searx/engines/yahoo_news.py +++ b/searx/engines/yahoo_news.py @@ -14,7 +14,6 @@ from datetime import datetime, timedelta from dateutil import parser from lxml import html -from searx import logger from searx.utils import ( eval_xpath_list, eval_xpath_getindex, @@ -23,8 +22,6 @@ from searx.utils import ( from searx.engines.yahoo import parse_url -logger = logger.getChild('yahoo_news engine') - # about about = { "website": 'https://news.yahoo.com',