Skip to content

Commit 013d14f

Browse files
committed
ragl.factory logging update
1 parent 4f50432 commit 013d14f

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

ragl/factory.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ def register_cls(cls, config_cls: type[RaglConfig], factory) -> None:
141141
_LOG.info('Registering factory class %s', cls.__name__)
142142
if not issubclass(config_cls, RaglConfig):
143143
msg = 'config_cls must be a subclass of RaglConfig'
144-
_LOG.critical(msg)
144+
_LOG.error(msg)
145145
raise TypeError(msg)
146146

147147
if not issubclass(factory, AbstractFactory):
148148
msg = 'cls must be a subclass of AbstractFactory'
149-
_LOG.critical(msg)
149+
_LOG.error(msg)
150150
raise TypeError(msg)
151151

152152
cls._factory_map[config_cls] = factory
@@ -195,26 +195,28 @@ def __call__(self, *args, **kwargs) -> Any:
195195
ConfigurationError:
196196
When no factory found for configuration type.
197197
"""
198-
_LOG.debug('Calling factory %s with args: %s, kwargs: %s',)
199198
if self.__class__.__name__ not in self.can_call_abstract__call__:
200199
msg = f'{self.__class__.__name__} cannot be called directly'
201-
_LOG.critical(msg)
200+
_LOG.error(msg)
202201
raise TypeError(msg)
203202

204203
try:
205204
config = kwargs['config']
206205
except KeyError as e:
207206
msg = 'config must be provided'
208-
_LOG.critical(msg)
207+
_LOG.error(msg)
209208
raise ConfigurationError(msg) from e
210209

211210
try:
212211
factory_cls = self._factory_map[type(config)]
213212
except KeyError as e:
214213
msg = f'No factory found for configuration type: {e}'
215-
_LOG.critical(msg)
214+
_LOG.error(msg)
216215
raise ConfigurationError(msg) from e
217216

217+
_LOG.debug('Calling factory %s with args: %s, kwargs: %s',
218+
self.__class__.__name__, args, kwargs)
219+
218220
factory = factory_cls()
219221
return factory(*args, **kwargs)
220222

@@ -306,15 +308,17 @@ class is not available.
306308
config = kwargs['config']
307309
except KeyError as e:
308310
msg = 'config parameter must be provided'
309-
_LOG.critical(msg)
311+
_LOG.error(msg)
310312
raise ConfigurationError(msg) from e
311313
try:
312314
# pylint: disable=import-outside-toplevel
315+
_LOG.info('Importing SentenceTransformerEmbedder')
313316
from ragl.embed.sentencetransformer import SentenceTransformerEmbedder # noqa: E501
317+
_LOG.info('Creating SentenceTransformerEmbedder instance')
314318
return SentenceTransformerEmbedder(config=config)
315319
except ImportError as e:
316320
msg = 'SentenceTransformerEmbedder not available'
317-
_LOG.critical(msg)
321+
_LOG.error(msg)
318322
raise ConfigurationError(msg) from e
319323

320324

@@ -355,27 +359,28 @@ def __call__(self, *args, **kwargs) -> Any:
355359
Keyword arguments containing 'config', 'dimensions',
356360
and 'index_name'.
357361
"""
358-
_LOG.debug('Calling RedisVectorStore %s with args: %s, kwargs: %s',)
359362
try:
360363
config = kwargs['config']
361364
dimensions = kwargs['dimensions']
362365
index_name = kwargs['index_name']
363366
except KeyError as e:
364367
msg = 'config, dimensions, and index_name must be provided'
365-
_LOG.critical(msg)
368+
_LOG.error(msg)
366369
raise ConfigurationError(msg) from e
367370

368371
try:
369372
# pylint: disable=import-outside-toplevel
373+
_LOG.info('Importing RedisVectorStore')
370374
from ragl.store.redis import RedisVectorStore
375+
_LOG.info('Creating RedisVectorStore instance')
371376
return RedisVectorStore(
372377
redis_config=config,
373378
dimensions=dimensions,
374379
index_name=index_name,
375380
)
376381
except ImportError as e:
377382
msg = 'RedisVectorStore not available'
378-
_LOG.critical(msg)
383+
_LOG.error(msg)
379384
raise ConfigurationError(msg) from e
380385

381386

tests/functional/ragl/test_factory.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,19 @@ def test_debug_logging_in_call(self):
462462
record.levelname == 'DEBUG']
463463
self.assertTrue(len(debug_messages) > 0)
464464

465-
def test_critical_logging_on_error(self):
466-
"""Test critical logging when errors occur."""
465+
def test_error_logging_on_error(self):
466+
"""Test logging when errors occur."""
467467
factory = EmbedderFactory()
468468

469-
with self.assertLogs('ragl.factory', level='CRITICAL') as log:
469+
with self.assertLogs('ragl.factory', level='ERROR') as log:
470470
try:
471471
factory() # Missing config
472472
except ConfigurationError:
473473
pass
474474

475475
# Verify critical messages are logged
476476
critical_messages = [record.levelname for record in log.records if
477-
record.levelname == 'CRITICAL']
477+
record.levelname == 'ERROR']
478478
self.assertTrue(len(critical_messages) > 0)
479479

480480

0 commit comments

Comments
 (0)