Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error logging java.sql.Date #1366

Closed
Hikarikun92 opened this issue Mar 14, 2023 · 0 comments
Closed

Error logging java.sql.Date #1366

Hikarikun92 opened this issue Mar 14, 2023 · 0 comments

Comments

@Hikarikun92
Copy link
Contributor

Description

When I have an instance of a java.sql.Date object and try to log it as a parameterized message, the newest version of Log4J assumes it's a regular java.util.Date one and tries to call Date.toInstant() when logging it. This works for java.util.Date and its subclasses java.sql.Timestamp and java.sql.Time (which uses a specific format for that type), but fails for java.sql.Date, as it throws an UnsupportedOperationException.

Configuration

Version: 2.20.0

Logs

ERROR StatusConsoleListener An exception occurred processing Appender Console
 java.lang.UnsupportedOperationException
	at java.sql/java.sql.Date.toInstant(Date.java:316)
	at org.apache.logging.log4j.message.ParameterFormatter.appendDate(ParameterFormatter.java:492)
	at org.apache.logging.log4j.message.ParameterFormatter.appendSpecialTypes(ParameterFormatter.java:485)
	at org.apache.logging.log4j.message.ParameterFormatter.recursiveDeepToString(ParameterFormatter.java:474)
	at org.apache.logging.log4j.message.ParameterFormatter.recursiveDeepToString(ParameterFormatter.java:449)
	at org.apache.logging.log4j.message.ParameterFormatter.formatMessage2(ParameterFormatter.java:192)
	at org.apache.logging.log4j.message.ParameterizedMessage.formatTo(ParameterizedMessage.java:227)
	at (...)
	at org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1407)
	at com.example.Log4JTest.test(Log4JTest.java:13)
	at (...)

Reproduction

log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
	<Appenders>
		<Console name="Console" target="SYSTEM_OUT" follow="true">
			<PatternLayout pattern="%d{MM-dd HH:mm:ss.SSS} %5p %c: %m%n%ex"/>
		</Console>
	</Appenders>
	<Loggers>
		<Root level="info">
			<AppenderRef ref="Console" />
		</Root>
	</Loggers>
</Configuration>

JUnit test:

public class Log4JTest {
    @Test
    void test() {
        Logger logger = LogManager.getLogger();
        logger.info("Test: {}", java.sql.Date.valueOf(LocalDate.now()));
    }
}
ppkarwasz pushed a commit that referenced this issue Mar 22, 2023
theit pushed a commit to theit/logging-log4j2 that referenced this issue May 30, 2023
theit pushed a commit to theit/logging-log4j2 that referenced this issue May 30, 2023
theit pushed a commit to theit/logging-log4j2 that referenced this issue May 30, 2023
ppkarwasz added a commit that referenced this issue Sep 20, 2023
ppkarwasz added a commit that referenced this issue Sep 20, 2023
LuciferYang added a commit to apache/spark that referenced this issue Oct 23, 2023
### What changes were proposed in this pull request?
This pr aims upgrade log4j from 2.20.0 to 2.21.0.

### Why are the changes needed?
Support for the zstd compression algorithm has been added in the new version: apache/logging-log4j2#1508 | apache/logging-log4j2#1514
Meanwhile, the new version starts to use Java 11 for building, and the runtime version is still compatible with Java 8: apache/logging-log4j2#1369
The new version also brings some bug fixes, such as:
- Fixed logging of java.sql.Date objects by appending it before Log4J tries to call java.util.Date.toInstant() on it: apache/logging-log4j2#1366
- Fixed concurrent date-time formatting issue in PatternLayout: apache/logging-log4j2#1485
- Fixed buffer size in Log4jFixedFormatter date time formatter: apache/logging-log4j2#1418
- Fixed the propagation of synchronous action failures in RollingFileManager and FileRenameAction: apache/logging-log4j2#1445 | apache/logging-log4j2#1549
- Fixed RollingFileManager to propagate failed synchronous actions correctly: apache/logging-log4j2#1445
and more.

The complete release note is as follows:
- https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.21.0

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Pass GitHub Actions

### Was this patch authored or co-authored using generative AI tooling?
No

Closes #43478 from LuciferYang/SPARK-45625.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
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

No branches or pull requests

1 participant