mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-08 04:56:45 +00:00
fix: move sensitive log to debug mode (#7230)
This commit is contained in:
parent
380052a963
commit
419009b495
@ -67,7 +67,9 @@ class TextLanguageRouter:
|
||||
def detect_language(self, text: str) -> Optional[str]:
|
||||
try:
|
||||
language = langdetect.detect(text)
|
||||
except langdetect.LangDetectException:
|
||||
logger.warning("Langdetect cannot detect the language of text: %s", text)
|
||||
except langdetect.LangDetectException as exception:
|
||||
logger.warning("Langdetect cannot detect the language of text. Error: %s", exception)
|
||||
# Only log the text in debug mode, as it might contain sensitive information
|
||||
logger.debug("Langdetect cannot detect the language of text: %s", text)
|
||||
language = None
|
||||
return language
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
---
|
||||
security:
|
||||
- |
|
||||
Remove the text value from a warning log in the `TextLanguageRouter` to avoid logging sensitive information.
|
||||
The text can be still be shown by switching to the `debug` log level.
|
||||
|
||||
```python
|
||||
import logging
|
||||
|
||||
logging.basicConfig(format="%(levelname)s - %(name)s - %(message)s", level=logging.WARNING)
|
||||
logging.getLogger("haystack").setLevel(logging.DEBUG)
|
||||
```
|
||||
@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import pytest
|
||||
from _pytest.logging import LogCaptureFixture
|
||||
|
||||
from haystack import Document
|
||||
from haystack.components.routers import TextLanguageRouter
|
||||
@ -38,8 +39,15 @@ class TestTextLanguageRouter:
|
||||
result = classifier.run(text=german_sentence)
|
||||
assert result == {"unmatched": german_sentence}
|
||||
|
||||
def test_warning_if_no_language_detected(self, caplog):
|
||||
def test_warning_if_no_language_detected(self, caplog: LogCaptureFixture):
|
||||
with caplog.at_level(logging.WARNING):
|
||||
classifier = TextLanguageRouter()
|
||||
classifier.run(text=".")
|
||||
assert "Langdetect cannot detect the language of text. Error: No features in text." in caplog.text
|
||||
|
||||
def test_warning_if_no_language_detected_if_debug(self, caplog: LogCaptureFixture):
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
classifier = TextLanguageRouter()
|
||||
classifier.run(text=".")
|
||||
assert "Langdetect cannot detect the language of text. Error: No features in text." in caplog.text
|
||||
assert "Langdetect cannot detect the language of text: ." in caplog.text
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user