Mailing List webobjects-dev@wocommunity.org Message #100
From: Paul Hoadley <webobjects-dev@wocommunity.org>
Subject: Re: [WO-DEV] Log4J 2.x
Date: Thu, 18 Mar 2021 12:31:55 +1030
To: WebObjects & WOnder Development <webobjects-dev@wocommunity.org>
On 15 Mar 2021, at 15:45, Paul Hoadley <webobjects-dev@wocommunity.org> wrote:

1. Is anyone using Log4J 2.x in a Wonder project? Is there a pain free way to migrate from 1.x → 2.x while retaining the convenience of Wonder's hierarchical Properties file loading?

The answer here is "yes", though it probably depends on your definition of "pain free".

1. Leaving aside the difference in syntax, it's easy enough to add log4j-slf4j-impl to your dependencies, add log4j2.properties to src/main/resources, and you're rolling with Log4J2. It's "retaining the convenience of Wonder's hierarchical Properties file loading" that adds the need for some additional gymnastics, but you can do it by creating a custom ConfigurationFactory that pulls Log4J2 properties out of system properties. You can use the Log4J2 mechanisms to indicate that your custom factory should be used, but, of course, it then gets loaded well before ERXProperties has done the hierarchical loading and merging with system properties. However, you can set some sensible defaults in the factory, and then re-run configuration in, say, your Application constructor.

2. You'll lose ERXPatternLayout, and along with it specifiers like '$' and '#' for application name and port, so adjust your patterns accordingly.

3. The convenience of setting log levels like this:

log4j.logger.er=INFO
log4j.logger.er.extensions.ERXDatabaseContextDelegate=WARN

is replaced by this:

app.logging.loggers=er,erdb
app.logging.logger.er.name=er
app.logging.logger.er.level=INFO
app.logging.logger.erdb.name=er.extensions.ERXDatabaseContextDelegate
app.logging.logger.erdb.level=WARN

So that's great. ("app.logging." is a custom prefix there, meaningful only to my custom ConfigurationFactory.) A project for a rainy day might be converting the former to the latter in the custom ConfigurationFactory.

If anyone wants more detail here, let me know.


-- 
Paul Hoadley
https://logicsquad.net/
https://www.linkedin.com/company/logic-squad/

Subscribe (FEED) Subscribe (DIGEST) Subscribe (INDEX) Unsubscribe Mail to Listmaster