All special characters in jobs/pods logs#177
All special characters in jobs/pods logs#177PeekLeon wants to merge 1 commit intorundeck-plugins:masterfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR improves the handling of special characters in Kubernetes pod and job logs by preserving non-ASCII characters like French accented letters (é, è, à, etc.) that were previously being stripped out. The change addresses an issue where the existing ASCII-only encoding was too restrictive and caused message truncation for internationalized content.
- Replaces direct ASCII encoding with a try-catch approach to preserve Unicode characters
- Adds fallback to ASCII encoding only when the primary logging fails
- Applies the fix consistently across both pod log reading and job waiting functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| contents/pods-read-logs.py | Updates log output handling to preserve Unicode characters with ASCII fallback |
| contents/job-wait.py | Applies the same Unicode-preserving log handling for job monitoring |
Comments suppressed due to low confidence (2)
contents/pods-read-logs.py:38
- The original code used print() but the new code uses log.info(). This changes the output destination and may break existing functionality that depends on stdout output.
try:
contents/pods-read-logs.py:50
- The original code used print() but the new code uses log.info(). This changes the output destination and may break existing functionality that depends on stdout output.
try:
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| print(line.encode('ascii', 'ignore')) | ||
| try: | ||
| log.info(line) | ||
| except: |
There was a problem hiding this comment.
Using a bare except clause is not recommended as it catches all exceptions, including system exits and keyboard interrupts. Consider catching specific exceptions like UnicodeError or UnicodeEncodeError instead.
| except: | |
| except UnicodeError: |
| print(line.encode('ascii', 'ignore')) | ||
| try: | ||
| log.info(line) | ||
| except: |
There was a problem hiding this comment.
Using a bare except clause is not recommended as it catches all exceptions, including system exits and keyboard interrupts. Consider catching specific exceptions like UnicodeError or UnicodeEncodeError instead.
| except: | |
| except UnicodeError: |
| log.info(line.encode('ascii', 'ignore')) | ||
| try: | ||
| log.info(line) | ||
| except: |
There was a problem hiding this comment.
Using a bare except clause is not recommended as it catches all exceptions, including system exits and keyboard interrupts. Consider catching specific exceptions like UnicodeError or UnicodeEncodeError instead.
| except: | |
| except UnicodeEncodeError: |
|
Thank you for addressing this! You're absolutely right that the current However, we'd like to suggest some improvements to your implementation: 1. Specific exception handling Instead of a bare try:
log.info(line)
except UnicodeEncodeError:
log.info(line.encode('ascii', 'ignore').decode('ascii'))2. Consistency in Your change switches from 3. Consider UTF-8 encoding Instead of falling back to ASCII, consider UTF-8 with error handling: try:
log.info(line)
except UnicodeEncodeError:
log.info(line.encode('utf-8', 'replace').decode('utf-8'))This would preserve more characters while still handling problematic ones gracefully. 4. Root cause consideration The original issue (#122) was a Could you update the PR to:
Thanks for helping improve international character support! |
Hi,
I have an issue with special characters disappearing from Kubernetes logs.
I noticed issue #122, which removes all non-ASCII characters, but this also filters out characters like é, è, à, etc., which causes my French messages to be truncated.
I would like to replace:
with:
I added the try/except as a fallback, but I believe it may not be necessary since log.info(line) already works fine.
Would this change be acceptable?
Here are some screenshots
logs output :

Job :

Wait-for :

Characters used : ✅ ! # $ % & ' ( )éèàùüêûîô * + , - . / ; < = > ? @ [ \ ] ^ _ ` { | } ~µ🧙
Thanks!