Skip to content

fix: only set logging level when explicitly requested#1551

Open
haoyu-haoyu wants to merge 1 commit intostanfordnlp:devfrom
haoyu-haoyu:fix/logging-separate-from-download
Open

fix: only set logging level when explicitly requested#1551
haoyu-haoyu wants to merge 1 commit intostanfordnlp:devfrom
haoyu-haoyu:fix/logging-separate-from-download

Conversation

@haoyu-haoyu
Copy link
Copy Markdown

Summary

download(), install_corenlp(), and Pipeline.__init__() all called set_logging_level() unconditionally, even when the caller passed neither logging_level nor verbose. This caused set_logging_level(None, None) to reset the stanza logger to INFO as a side effect, overriding any logging configuration the user had set up.

Closes #1418

Problem

import logging
import stanza

# User configures logging to WARNING
stanza.logger.setLevel('WARNING')

# This silently resets it to INFO
stanza.download('en')

# User's WARNING level is gone
print(stanza.logger.level)  # 20 (INFO), not 30 (WARNING)

Fix

Guard all three call sites so set_logging_level() is only invoked when the caller explicitly passes logging_level or verbose:

# Before (always called, even with defaults):
set_logging_level(logging_level, verbose)

# After (only when user requested):
if logging_level is not None or verbose is not None:
    set_logging_level(logging_level, verbose)

Files changed

File Call site
stanza/resources/common.py download()
stanza/resources/installation.py install_corenlp()
stanza/pipeline/core.py Pipeline.__init__()

Backward compatibility

  • Users who pass logging_level='DEBUG' or verbose=True get the same behavior as before
  • Users who don't pass either argument no longer have their logging silently reset
  • stanza.download('en', logging_level='ERROR') still works

download(), install_corenlp(), and Pipeline.__init__ all called
set_logging_level() unconditionally, even when the caller passed
neither logging_level nor verbose. This caused set_logging_level()
to reset the logger to INFO as a side effect, overriding any
logging configuration the user had set up.

Guard all three call sites so set_logging_level() is only invoked
when the caller explicitly passes logging_level or verbose. When
both are None (the default), the user's existing logging setup is
left untouched.

Closes stanfordnlp#1418
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant