summaryrefslogtreecommitdiff
path: root/searx/engines/__init__.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-09-09 17:21:48 +0200
committerAlexandre Flament <alex@al-f.net>2021-09-13 08:47:59 +0200
commitf8793fbda031928222613c3080ec65584d860984 (patch)
tree80bc6e7876f0202ea17e3dfdbec9a45e91a7954d /searx/engines/__init__.py
parent1973e4ecf691f173299fb11abc61750009bdef84 (diff)
downloadsearxng-f8793fbda031928222613c3080ec65584d860984.tar.gz
searxng-f8793fbda031928222613c3080ec65584d860984.zip
[fix] logger per engine: make .logger is always initialized
the openstreetmap engine imports code from the wikidata engine. before this commit, specific code make sure to copy the logger variable to the wikidata engine. with this commit searx.engines.load_engine makes sure the .logger is initialized. The implementation scans sys.modules for module name starting with searx.engines.
Diffstat (limited to 'searx/engines/__init__.py')
-rw-r--r--searx/engines/__init__.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/searx/engines/__init__.py b/searx/engines/__init__.py
index 154cd605f..e0b5796e4 100644
--- a/searx/engines/__init__.py
+++ b/searx/engines/__init__.py
@@ -110,10 +110,26 @@ def load_engine(engine_data):
if is_missing_required_attributes(engine):
return None
- engine.logger = logger.getChild(engine_name)
+ set_loggers(engine, engine_name)
+
return engine
+def set_loggers(engine, engine_name):
+ # set the logger for engine
+ engine.logger = logger.getChild(engine_name)
+ # the engine may have load some other engines
+ # may sure the logger is initialized
+ for module_name, module in sys.modules.items():
+ if (
+ module_name.startswith("searx.engines")
+ and module_name != "searx.engines.__init__"
+ and not hasattr(module, "logger")
+ ):
+ module_engine_name = module_name.split(".")[-1]
+ module.logger = logger.getChild(module_engine_name)
+
+
def update_engine_attributes(engine, engine_data):
# set engine attributes from engine_data
for param_name, param_value in engine_data.items():