ramanathan1504 commented on PR #4128:
URL: https://github.com/apache/logging-log4j2/pull/4128#issuecomment-4532132133
@ashr123
Thanks for this work and the continuation from #3789! The internal
refactoring in DatePatternConverter looks much cleaner now.
However, from a backward-compatibility and public API perspective,
introducing NamedInstantPattern as a public enum is a heavy commitment. It
permanently locks the public API into this specific Enum and prevents users
from easily extending named patterns via plugins (since Enums are strictly
final at compile-time).
To achieve both your goal (making patterns programmatically accessible) and
protecting the public API, I suggest a hybrid approach:
1. Hide the Enum: Remove the public modifier from NamedInstantPattern so it
becomes package-private. It remains a great internal routing tool for
DatePatternConverter.
2. Expose Public String Constants Instead: Create a simple public utility
class to hold the strings. This gives users the exact IDE
auto-complete/compile-time safety they had with FixedDateFormat, but strings
are inlined by the compiler, meaning zero backward-compatibility burden for
Log4j in the future.
```java
public final class InstantPatterns {
private InstantPatterns() {} // prevent instantiation
public static final String ABSOLUTE = "HH:mm:ss,SSS";
public static final String DEFAULT = "yyyy-MM-dd HH:mm:ss,SSS";
public static final String ISO8601 = "yyyy-MM-dd'T'HH:mm:ss,SSS";
// ...
}
```
This approach gives users the programmatic access they need
(InstantPatterns.ISO8601) while keeping our public API surface as flat and safe
as possible."
--
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]