Skip to content

tail -f garbled output when log has Korean characters #1693

@Jamongss

Description

@Jamongss

개요

  • python3.10 / supervisor-4.2.5 기준
  • supervisor tail -f 입력 시 한글이 깨지는 예외 처리
  • supervisor> tail -f service_name 명령어로 실시간 로그 출력 시 기존에 찍힌 문자를 불러오는 과정에서 인코딩/디코딩 로직 예외 발생 -> 한글이 깨져서 출력 됨
  • 기존 문자를 읽어올 때만 깨져서 보이고 커맨드 입력 시점 이후 터미널에 찍히는 실시간 로그는 정상으로 출력 됨

원인

  • tail -f 입력 시 설정된 초기 head 길이로 byte를 읽어올 때 한글이 잘리면서 깨진 문자열을 그대로 출력(설정된 head 값보다 적은 양의 로그를 불러올 때는 깨짐 현상 없음)
  • 맨 앞 잘린 문자열만 깨져 보여야 하지만 이후 나머지 문자열도 모두 깨져서 출력 됨
  • 실시간으로 찍히는 로그는 정상 출력 됨
  • decode 처리하는 부분에서 예외 처리가 되지 않음

수정 내용

  • compat.py

AS-IS

  - 54 line: return s.encode(encoding)
  - 60 line: return s.decode(encoding)

TO-BE

  - 54 line: return s.encode(encoding, errors='replace')
  - 60 line: return s.decode(encoding, errors='replace')

수정 후

  • 인입된 bytes에서 깨진 부분은 '�'로 표시하고 나머지 부분은 정상적으로 decode 진행
  • 깨진 문자를 대체 문자(�)로 표시하여 처리 연속성 보장
  • 잘못된 인코딩이나 깨진 바이트 데이터로 인한 UnicodeDecodeError/UnicodeEncodeError
    예외 방지

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions