add ensure_ascii param
feat: https://github.com/elastic/ecs-logging-python/issues/170
💚 CLA has been signed
:robot: GitHub comments
Just comment with:
rundocs-build: Re-trigger the docs validation. (use unformatted text in the comment!)
run docs-build
Thanks for the PR, haven't looked closely at the code but this needs some tests and some docs update in
docs/setup.asciidocin order to be merged.
Thanks for the feedback! I've addressed both points:
Tests Added
I've added comprehensive test coverage for the ensure_ascii parameter:
For StdlibFormatter (5 new tests in tests/test_stdlib_formatter.py):
- Tests for default behavior (ensure_ascii=True)
- Tests for explicit True/False values
- Tests with emojis and Unicode characters (Chinese, etc.)
- Tests with extra fields containing non-ASCII characters
For StructlogFormatter (5 new tests in tests/test_structlog_formatter.py):
- Similar comprehensive coverage for the structlog formatter
- All tests verify both the JSON output format and correct parsing
All tests verify that:
- Non-ASCII characters are properly escaped when
ensure_ascii=True(default) - Non-ASCII characters are preserved when
ensure_ascii=False - The output is always valid JSON
Documentation Updated
I've added documentation to docs/reference/installation.md (note: this project uses markdown docs rather than asciidoc). The documentation includes:
- A new section "Controlling ASCII encoding" for
StdlibFormatter - A new section "Controlling ASCII encoding for Structlog" for
StructlogFormatter - Code examples showing both default and custom behavior
- Explanation of use cases for internationalized applications
Please let me know if you'd like any changes or have additional feedback!
Looks great. Thanks for adding docs and tests!
Thanks! I've also reformatted the code to ensure consistency. The changes are now ready for review.