ecs-logging-python icon indicating copy to clipboard operation
ecs-logging-python copied to clipboard

add ensure_ascii param

Open k8scat opened this issue 1 month ago • 5 comments

feat: https://github.com/elastic/ecs-logging-python/issues/170

k8scat avatar Nov 14 '25 07:11 k8scat

💚 CLA has been signed

:robot: GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)

github-actions[bot] avatar Nov 14 '25 07:11 github-actions[bot]

run docs-build

k8scat avatar Nov 14 '25 07:11 k8scat

🔍 Preview links for changed docs

github-actions[bot] avatar Nov 19 '25 17:11 github-actions[bot]

Thanks for the PR, haven't looked closely at the code but this needs some tests and some docs update in docs/setup.asciidoc in 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!

k8scat avatar Nov 19 '25 17:11 k8scat

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.

k8scat avatar Nov 24 '25 07:11 k8scat