Repository navigation
Write the log file as UTF-8 - #2448
Merged
Merged
Conversation
logging.FileHandler(log_file) used the locale encoding, so non-ASCII queries or data raised UnicodeEncodeError in the log handler on non-UTF-8 locales (for example Windows cp1252). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Contributor
|
Thank you! |
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.
Description
With the default
log_file = ~/.mycli.logandlog_level = INFO, the REPL logs failed queries assql: %r, error: %r.initialize_logging()builds that handler aslogging.FileHandler(log_file)without anencoding, so the file is opened with the locale encoding. On Python 3.11–3.14 with a non-UTF-8 locale (for example Windows cp1252), a failed query containing characters outside that codepage makes the handler raiseUnicodeEncodeError: Python prints a--- Logging error ---traceback to the terminal and the log entry is lost. The audit log, the-llogfile option and the config files already open their files as UTF-8.Fix: pass
encoding='utf-8'to theFileHandler, plus achangelog.mdentry.Test:
test_initialize_logging_file_handler_uses_utf8asserts the handler's encoding is UTF-8. It fails on main under Python 3.12 (the encoding isNone) and passes with the fix. On 3.15 the default is already UTF-8, so the test is only red on earlier versions.This PR was prepared with the assistance of an AI coding tool (Claude Code).
Checklist
changelog.mdfile.mycli/AUTHORS.txtfile (or it's already there).