GitHub user ppkarwasz added a comment to the discussion: Getting current 
date-time format (or default format)

> I'm not trying to introspect anything, but I do `println` (in addition to 
> logs) some data I got from `HttpClient` and I'm printing dates (as 
> Last-Modified) with the default pattern cause I want my logs and my output to 
> be format the same way.

That’s a nice detail—keeping your output visually consistent with the logs can 
be quite helpful!

That said, have you considered what happens if someone changes the logging 
pattern or switches from console to file logging? In such cases, your `println` 
output might no longer match. If consistency is important, it might be more 
robust to use the logger itself for that kind of output rather than relying on 
`System.out`.

Would you be open to sharing a code snippet? There might already be a built-in 
feature or a cleaner workaround we can suggest.

> In addition, why can't all the named patterns be an enum with 3 fields (base 
> pattern, compact postfix and non-compact postfix) and a getter with a 
> `boolean compact` parameter that returns the correct pattern?

They could, technically—and you're welcome to propose that in a PR.

That said, a few considerations:

* I'm not sure there's a strong case for making such an `enum` public. Unless 
there's a clear user-facing need, we prefer to keep our API surface area minimal
* The postfixes aren’t “compact” and “non-compact.” One follows 
`DateTimeFormatter` syntax (Java 8 time), and the other follows 
`SimpleDateFormat`/Commons Lang `FastDateFormat` conventions. So the 
distinction isn’t formatting style—the postfixes give the same result but using 
different APIs.



GitHub link: 
https://github.com/apache/logging-log4j2/discussions/3788#discussioncomment-13601110

----
This is an automatically sent email for dev@logging.apache.org.
To unsubscribe, please send an email to: dev-unsubscr...@logging.apache.org

Reply via email to