Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Tweak/adjust the logging verbosity greater-eq to warning level #147

Merged
merged 4 commits into from Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .codecov.yml
@@ -0,0 +1,8 @@
coverage:
status:
project:
default:
target: 88%
threshold: null
patch: false
changes: false
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- [Short description of non-trivial change.]

### Changed
- Moderating the logging impact (since 2.0.8) for specific environments (PR #147)

### Fixed
- Wrong logging level applied when setting kwarg `explain` to True (PR #146)

Expand Down
20 changes: 9 additions & 11 deletions charset_normalizer/api.py
Expand Up @@ -70,21 +70,19 @@ def from_bytes(
if explain:
previous_logger_level = logger.level # type: int
logger.addHandler(explain_handler)
logger.setLevel(logging.INFO)
logger.setLevel(logging.DEBUG)

length = len(sequences) # type: int

if length == 0:
logger.warning(
"Given content is empty, stopping the process very early, returning empty utf_8 str match"
)
logger.warning("Encoding detection on empty bytes, assuming utf_8 intention.")
if explain:
logger.removeHandler(explain_handler)
logger.setLevel(previous_logger_level or logging.WARNING)
return CharsetMatches([CharsetMatch(sequences, "utf_8", 0.0, False, [], "")])

if cp_isolation is not None:
logger.warning(
logger.debug(
"cp_isolation is set. use this flag for debugging purpose. "
"limited list of encoding allowed : %s.",
", ".join(cp_isolation),
Expand All @@ -94,7 +92,7 @@ def from_bytes(
cp_isolation = []

if cp_exclusion is not None:
logger.warning(
logger.debug(
"cp_exclusion is set. use this flag for debugging purpose. "
"limited list of encoding excluded : %s.",
", ".join(cp_exclusion),
Expand All @@ -104,7 +102,7 @@ def from_bytes(
cp_exclusion = []

if length <= (chunk_size * steps):
logger.warning(
logger.debug(
"override steps (%i) and chunk_size (%i) as content does not fit (%i byte(s) given) parameters.",
steps,
chunk_size,
Expand Down Expand Up @@ -190,7 +188,7 @@ def from_bytes(
) # type: bool

if encoding_iana in {"utf_16", "utf_32"} and not bom_or_sig_available:
logger.info(
logger.debug(
"Encoding %s wont be tested as-is because it require a BOM. Will try some sub-encoder LE/BE.",
encoding_iana,
)
Expand Down Expand Up @@ -221,7 +219,7 @@ def from_bytes(
)
except (UnicodeDecodeError, LookupError) as e:
if not isinstance(e, LookupError):
logger.warning(
logger.debug(
"Code page %s does not fit given bytes sequence at ALL. %s",
encoding_iana,
str(e),
Expand All @@ -237,7 +235,7 @@ def from_bytes(
break

if similar_soft_failure_test:
logger.warning(
logger.info(
"%s is deemed too similar to code page %s and was consider unsuited already. Continuing!",
encoding_iana,
encoding_soft_failed,
Expand Down Expand Up @@ -332,7 +330,7 @@ def from_bytes(
) # type: float
if mean_mess_ratio >= threshold or early_stop_count >= max_chunk_gave_up:
tested_but_soft_failure.append(encoding_iana)
logger.warning(
logger.info(
"%s was excluded because of initial chaos probing. Gave up %i time(s). "
"Computed mean chaos is %f %%.",
encoding_iana,
Expand Down