Fix duplicate log messages by disabling log propagation by default#7937
Open
tboerstad wants to merge 2 commits intohuggingface:mainfrom
Open
Fix duplicate log messages by disabling log propagation by default#7937tboerstad wants to merge 2 commits intohuggingface:mainfrom
tboerstad wants to merge 2 commits intohuggingface:mainfrom
Conversation
This PR fixes an issue where applications that configure logging see duplicate messages from `datasets`:
```python
import logging
logging.basicConfig(level=logging.WARNING)
from datasets.utils.logging import get_logger
get_logger("datasets.load").warning("This appears twice")
```
Outputs:
```
This appears twice
WARNING:datasets.load:This appears twice
```
This non-standard behaviour breaks default logging behaviour.
The docstring for `disable_propagation()` incorrectly says:
[Note that log propagation is disabled by default](https://github.com/huggingface/datasets/blob/6a1bc355a0ca2c8f9f5c10698215212f0f14e7b7/src/datasets/utils/logging.py#L161C1-L162C1)
Perhaps this was copied over from `transformers`, which disables log propogation by default, unless it's running under CI?
[library_root_logger.propagate = is_ci
](https://github.com/huggingface/transformers/blob/37974267efefe020168ff27081fbab8bbce04720/src/transformers/utils/logging.py#L103)
To restore the old behaviour, users can do:
```
import datasets
datasets.logging.enable_propagation()
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where applications that configure logging see duplicate messages from
datasets:Outputs:
This non-standard behaviour breaks default logging behaviour. The docstring for
disable_propagation()incorrectly says: Note that log propagation is disabled by defaultPerhaps this was copied over from
transformers, which disables log propogation by default, unless it's running under CI? library_root_logger.propagate = is_ciTo restore the old behaviour, users can do: