You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Natasha D'Silva <nd...@ca.ibm.com> on 2022/03/02 17:38:26 UTC

Looking up a system property specified in a log4j v1 properties file

I'm using log4j v2, the log4j v1 bridge and a v1 log4j.properties file that specifies an appender like this:

log4j.appender.KRFTRACE=${abc.def.log4j.appender.KRFTRACE}
log4j.rootLogger=ALL, KRFTRACE

I set the system property abc.def.log4j.appender.KRFTRACE to the appropriate class.
Previously, with log4j v2.13.3, this worked, you can see from the logs:


DEBUG StatusLogger Parsing for [root] with value=[ALL, KRFTRACE].
DEBUG StatusLogger Level token is [ALL].
DEBUG StatusLogger Logger root level set to ALL
DEBUG StatusLogger Parsing appender named "abc.def.TRACE".
DEBUG StatusLogger Adding appender named [KRFTRACE] to loggerConfig [].
DEBUG StatusLogger Level token is [ALL].
...
DEBUG StatusLogger Finished configuring.

But in v2.17.1, I get this error:


DEBUG StatusLogger Parsing for [root] with value=[ALL, KRFTRACE].
DEBUG StatusLogger Level token is [ALL].
DEBUG StatusLogger Logger root level set to ALL
DEBUG StatusLogger Parsing appender named "KRFTRACE".
ERROR StatusLogger Unable to create Appender ${abc.def.log4j.appender.KRFTRACE} due to ClassNotFoundException:${abc.def.log4j.appender.KRFTRACE}

Instead of checking the system property for the class name, the logger tries to use the lookup key "{abc.def.log4j.appender.KRFTRACE} " as the class name.
I have confirmed that the system property is set correctly.

I know from the doc that in v2 system properties are specified with the "${sys:}" prefix, but up until now it seemed to support both the  {} and {sys:} prefix for system properties. Are both supported or was it working in 2.13.3 by accident?
It isn't trivial to experiment with changing the properties file so I wanted to ask if this is a new bug or the previous behaviour in 2.13.3 was wrong and the properties file should always have used the "${sys:} prefix.

Thank you.

RE: Looking up a system property specified in a log4j v1 properties file

Posted by Natasha D'Silva <nd...@ca.ibm.com>.
HI,
I tried that and it worked. Thank you!


Re: Looking up a system property specified in a log4j v1 properties file

Posted by Gary Gregory <ga...@gmail.com>.
We just released 2.17.2 which contain many improvements to the 1.2 bridge.
Would you give it a try?

Gary


On Wed, Mar 2, 2022, 12:38 Natasha D'Silva <nd...@ca.ibm.com> wrote:

> I’m using log4j v2, the log4j v1 bridge and a v1 log4j.properties file
> that specifies an appender like this:
>
>
>
> log4j.appender.KRFTRACE=${abc.def.log4j.appender.KRFTRACE}
>
> log4j.rootLogger=ALL, KRFTRACE
>
>
>
> I set the system property abc.def.log4j.appender.KRFTRACE to the
> appropriate class.
>
> Previously, with log4j v2.13.3, this worked, you can see from the logs:
>
>
>
>
>
> DEBUG StatusLogger Parsing for [root] with value=[ALL, KRFTRACE].
>
> DEBUG StatusLogger Level token is [ALL].
>
> DEBUG StatusLogger Logger root level set to ALL
>
> DEBUG StatusLogger Parsing appender named "abc.def.TRACE".
>
> DEBUG StatusLogger Adding appender named [KRFTRACE] to loggerConfig [].
>
> DEBUG StatusLogger Level token is [ALL].
>
> ...
>
> DEBUG StatusLogger Finished configuring.
>
>
>
> But in v2.17.1, I get this error:
>
>
>
>
>
> DEBUG StatusLogger Parsing for [root] with value=[ALL, KRFTRACE].
>
> DEBUG StatusLogger Level token is [ALL].
>
> DEBUG StatusLogger Logger root level set to ALL
>
> DEBUG StatusLogger Parsing appender named "KRFTRACE".
>
> ERROR StatusLogger Unable to create Appender
> ${abc.def.log4j.appender.KRFTRACE} due to
> ClassNotFoundException:${abc.def.log4j.appender.KRFTRACE}
>
>
>
> Instead of checking the system property for the class name, the logger
> tries to use the lookup key “{abc.def.log4j.appender.KRFTRACE} “ as the
> class name.
>
> I have confirmed that the system property is set correctly.
>
>
>
> I know from the doc that in v2 system properties are specified with the
> “${sys:}” prefix, but up until now it seemed to support both the  {} and
> {sys:} prefix for system properties. Are both supported or was it working
> in 2.13.3 by accident?
>
> It isn’t trivial to experiment with changing the properties file so I
> wanted to ask if this is a new bug or the previous behaviour in 2.13.3 was
> wrong and the properties file should always have used the “${sys:} prefix.
>
>
>
> Thank you.
>