44import json
55import inspect
66import asyncio
7- import logging
87import pkgutil
98from collections import defaultdict
109from importlib import import_module
1312from fastapi import FastAPI , APIRouter
1413
1514from opa .utils import unique , filter_dict_to_function
16- from opa import config
15+ from opa import config , log
1716
1817
1918class BasePlugin :
@@ -146,12 +145,13 @@ def register_driver(self, driver: Driver):
146145 raise Exception (
147146 f'Driver with this name ({ name } ) already exists. CaSe of driver is ignored.'
148147 )
149- logging .debug (f'Registered driver { name } ' )
148+ log .debug (f'Registered driver { name } ' )
150149 self .drivers [name ] = driver
151150
152151 def _preload_drivers (self ):
153152 for name , values in config .OPTIONAL_COMPONENTS .items ():
154- name = name .lower ()
153+ name = name .lower () | log
154+ {'test' : 123 } | log
155155 load = values .get ('LOAD' , 'auto' )
156156 if load == 'no' :
157157 continue
@@ -168,7 +168,7 @@ def _preload_drivers(self):
168168 driverinstance .pm = self
169169 self .optional_components [name ] = driverinstance
170170
171- logging .info (
171+ log .info (
172172 f'Connecting to { name } with driver { drivername } , using { driverinstance .opts } '
173173 )
174174 yield driverinstance
@@ -183,7 +183,7 @@ async def load_components(self):
183183 def load_sync_components_global (self ):
184184 for driverinstance in self ._preload_drivers ():
185185 if asyncio .iscoroutinefunction (driverinstance .connect ):
186- logging .debug (f'Driver { driverinstance .name } is async, wont load' )
186+ log .debug (f'Driver { driverinstance .name } is async, wont load' )
187187 else :
188188 driverinstance .initialize ()
189189
@@ -273,7 +273,7 @@ def _get_plugindata():
273273 else config .PLUGIN_PATHS
274274 ) + ['/data/opa/plugins' ]
275275
276- logging .info (
276+ log .info (
277277 'Plugin loading settings:'
278278 f' plugin-paths: { PLUGIN_PATHS } \n '
279279 f' whitelist-regex: { PLUGIN_WHITELIST_RE } \n '
@@ -303,16 +303,16 @@ def _get_plugindata():
303303 else :
304304 metafile = f'{ allow_match } -meta.json'
305305
306- logging .debug ('' )
307- logging .debug (f'Checking if we should load "{ allow_match } "' )
306+ log .debug ('' )
307+ log .debug (f'Checking if we should load "{ allow_match } "' )
308308
309309 if os .path .exists (metafile ):
310- logging .debug (f'Found metafile @ { metafile } ' )
310+ log .debug (f'Found metafile @ { metafile } ' )
311311 metadata = json .load (open (metafile , 'r' ))
312312 else :
313- logging .debug (f'Metafile @ { metafile } does not exist, using empty metadata' )
313+ log .debug (f'Metafile @ { metafile } does not exist, using empty metadata' )
314314 metadata = {}
315- logging .debug (f'Metadata: { metadata } ' )
315+ log .debug (f'Metadata: { metadata } ' )
316316
317317 load_checks = {}
318318
@@ -347,12 +347,12 @@ def _get_plugindata():
347347 )
348348
349349 load = all (load_checks .values ())
350- logging .debug (f'Load-checks: { load_checks } , overall({ load } )' )
350+ log .debug (f'Load-checks: { load_checks } , overall({ load } )' )
351351
352352 if not load :
353353 continue
354354
355- logging .info (f'Loading plugin: { plugin .name } ' )
355+ log .info (f'Loading plugin: { plugin .name } ' )
356356
357357 """
358358 We should consider using lazy-loading instead of import_module.
0 commit comments