Zhuoxi2000 opened a new issue, #1494:
URL: https://github.com/apache/flink-agents/issues/1494

   ### Search before asking
   
   - [x] I searched in the 
[issues](https://github.com/apache/flink-agents/issues) and found nothing 
similar.
   
   ### Description
   
   Trace Log files are written in the JVM default charset, not UTF-8.
   
   - `FileTraceLogger.open()` creates its writer with `new 
FileWriter(logFilePath, true)` 
(`runtime/src/main/java/org/apache/flink/agents/runtime/tracelog/FileTraceLogger.java`).
   - `Slf4jTraceLogger.ensureLog4j2AppenderConfigured()` builds the layout of 
the automatic `{log.file}.trace-log.log` appender with 
`PatternLayout.newBuilder().withPattern("%msg%n").build()`, which also uses the 
default charset.
   
   On JDK 11 and 17 the default charset follows the locale (`file.encoding`), 
so with a non-UTF-8 locale such as `LANG=C`, or on Windows:
   
   - Expected: records are UTF-8 JSON, which is what the Trace Tree reader 
reads (`path.read_text(encoding="utf-8")` in 
`python/flink_agents/cli/trace_tree.py`).
   - Actual: characters outside the default charset are replaced with `?` and 
cannot be recovered; with a single-byte charset such as ISO-8859-1 the file is 
not valid UTF-8 and the reader reports `UNREADABLE_FILE`.
   
   JDK 18+ defaults to UTF-8, so it is not affected unless `file.encoding` is 
overridden.
   
   ### How to reproduce
   
   Add this test to `FileTraceLoggerTest` and run it with a non-UTF-8 default 
charset (it passes when the default charset is UTF-8):
   
   ```java
   @Test
   void testNonAsciiTextIsWrittenAsUtf8() throws Exception {
       String text = "你好 café 😀";
       logger.open(openParams);
       append(logger, new TestCustomEvent(text, 1), null, 
TraceLogLevel.VERBOSE);
       logger.flush();
   
       String line = Files.readString(getExpectedLogFilePath(), 
StandardCharsets.UTF_8);
       assertEquals(text, 
objectMapper.readTree(line).at("/attributes/customData").asText());
   }
   ```
   
   ```bash
   JAVA_TOOL_OPTIONS=-Dfile.encoding=ISO-8859-1 mvn test -pl runtime 
-Dtest=FileTraceLoggerTest#testNonAsciiTextIsWrittenAsUtf8
   ```
   
   It fails with `MalformedInputException` when the file is read as UTF-8.
   
   ### Version and environment
   
   main at f8a21ce6, Java 17, macOS
   
   ### Are you willing to submit a PR?
   
   - [x] I'm willing to submit a PR!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to