Skip to content

Conversation

@PeekLeon
Copy link

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:

log.info(line.encode('ascii', 'ignore'))

with:

try:
    log.info(line)
except:
    log.info(line.encode('ascii', 'ignore'))

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 :
all-chars

Job :
job

Wait-for :
wait-for

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

Thanks!

@fdevans fdevans requested a review from Copilot August 26, 2025 18:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
except:
except UnicodeError:

Copilot uses AI. Check for mistakes.
print(line.encode('ascii', 'ignore'))
try:
log.info(line)
except:
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
except:
except UnicodeError:

Copilot uses AI. Check for mistakes.
log.info(line.encode('ascii', 'ignore'))
try:
log.info(line)
except:
Copy link

Copilot AI Aug 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
except:
except UnicodeEncodeError:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant