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 Arulkumar Ponnusamy <pa...@gmail.com> on 2022/03/23 05:43:16 UTC

Reg: Needs help on logging issues on log4j2 latest version 2.17.2

 Hi all,
I am currently working on upgrading my log4j framework from 1.x to
2.x(latest) and my application is deployed in the wildfly. As part of our
application, we provide the provision to change the log level at runtime.
Am facing a peculiar issue where the logging is working(changing the log
level) with the 2.17.1 version whereas the same is not working with 2.17.2.
The change of log level works only if you change it via log4j2.properties
files.

any pointers on solving this would be great help
Thanks
Arulkumar Ponnusamy

Re: Reg: Needs help on logging issues on log4j2 latest version 2.17.2

Posted by Arulkumar Ponnusamy <pa...@gmail.com>.
Thanks So much for the clarification Piotr. Will look into the
ContextSelector section.

Thanks and regards
Arulkumar Ponnusamy


On Thu, Mar 24, 2022 at 2:21 PM Piotr P. Karwasz <pi...@gmail.com>
wrote:

> Hi Arulkumar,
>
> On Thu, 24 Mar 2022 at 07:30, Arulkumar Ponnusamy <pa...@gmail.com>
> wrote:
>
> > However, What i noticed is, the Configurator.setLevel() method's
> > Logger.getContext has a different reference id whereas the actual class's
> > LoggerFactory.getLogger(class) has a different context id. I guess,
> because
> > of this, the update does not send the notification properly so that the
> > actual change is not reflected. Attached the snapshot, the first image is
> > for the level setting using *Configurator.setlevel(*) and the second
> > image is the actual class where actual logs are printed.
> > what i noticed is, when the
> >
>
> Images are not accepted in the mailing list, please provide any code as
> text.
>
> The problem you are observing is due to the caller sensitivity of various
> Log4j2 functions, which have an implicit `LoggerContext` parameter. The
> change in behavior you observe is due to the fix of LOG4J-3330[1]. The fix
> itself is correct, as far as I can tell, but it modifies your program's
> behavior: `Configurator#setLevel` updates the `LoggerContext` associated
> with the classloader of the caller.
>
> I don't know the specifics of how WildFly manages classloaders, but IIRC
> there can be multiple classloaders per application. You should consider
> swapping the default `ClassLoaderContextSelector` (see
> https://logging.apache.org/log4j/2.x/manual/extending.html#ContextSelector
> )
> with something better suited for full Java EE application servers. I
> believe the `JndiContextSelector` might be the right choice.
>
> Piotr
>
> [1] https://issues.apache.org/jira/browse/LOG4J2-3330
>

Re: Reg: Needs help on logging issues on log4j2 latest version 2.17.2

Posted by "Piotr P. Karwasz" <pi...@gmail.com>.
Hi Arulkumar,

On Thu, 24 Mar 2022 at 07:30, Arulkumar Ponnusamy <pa...@gmail.com>
wrote:

> However, What i noticed is, the Configurator.setLevel() method's
> Logger.getContext has a different reference id whereas the actual class's
> LoggerFactory.getLogger(class) has a different context id. I guess, because
> of this, the update does not send the notification properly so that the
> actual change is not reflected. Attached the snapshot, the first image is
> for the level setting using *Configurator.setlevel(*) and the second
> image is the actual class where actual logs are printed.
> what i noticed is, when the
>

Images are not accepted in the mailing list, please provide any code as
text.

The problem you are observing is due to the caller sensitivity of various
Log4j2 functions, which have an implicit `LoggerContext` parameter. The
change in behavior you observe is due to the fix of LOG4J-3330[1]. The fix
itself is correct, as far as I can tell, but it modifies your program's
behavior: `Configurator#setLevel` updates the `LoggerContext` associated
with the classloader of the caller.

I don't know the specifics of how WildFly manages classloaders, but IIRC
there can be multiple classloaders per application. You should consider
swapping the default `ClassLoaderContextSelector` (see
https://logging.apache.org/log4j/2.x/manual/extending.html#ContextSelector)
with something better suited for full Java EE application servers. I
believe the `JndiContextSelector` might be the right choice.

Piotr

[1] https://issues.apache.org/jira/browse/LOG4J2-3330

Re: Reg: Needs help on logging issues on log4j2 latest version 2.17.2

Posted by Arulkumar Ponnusamy <pa...@gmail.com>.
Hi Piotr,
Thanks for the response.
Yes. Below is the actual code which I am using to set the log level.
*Configurator.setlevel("com.thridparty",Level.DEBUG); *

I see this problem happens only on my wildfly deployment whereas it is
working in standalone mode. am using the  -Dlog4j.configurationFile
property and my log4j2.properties files and my log4j2.properties file looks
as

appenders = console,thirdparty
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy/MM/dd HH:mm:ss} %-5p [%c] %msg%n

appender.thirdparty.type = RollingFile
appender.thirdparty.name = Thirdparty
appender.thirdparty.fileName=${sys:jboss.server.base.dir}/thirdparty.log
appender.thirdparty.filePattern=
${sys:jboss.server.base.dir}/thirdparty.log.%i
appender.thirdparty.layout.type=PatternLayout
appender.thirdparty.layout.pattern=%d %-5p [%c] (%t) %msg%n
appender.thirdparty.policies.type = Policies
appender.thirdparty.policies.size.type = SizeBasedTriggeringPolicy
appender.thirdparty.policies.size.size=10KB
appender.thirdparty.strategy.type = DefaultRolloverStrategy
appender.thirdparty.strategy.fileIndex = min
appender.thirdparty.strategy.max = 8

logger.maverick.name=com.thridparty
logger.maverick.additivity=false
logger.maverick.appenderRefs = Thirdparty
logger.maverick.appenderRef.file.ref = Thirdparty

rootLogger.level = ERROR
rootLogger.appenderRefs = console
rootLogger.appenderRef.stdout.ref = STDOUT

However, What i noticed is, the Configurator.setLevel() method's
Logger.getContext has a different reference id whereas the actual class's
LoggerFactory.getLogger(class) has a different context id. I guess, because
of this, the update does not send the notification properly so that the
actual change is not reflected. Attached the snapshot, the first image is
for the level setting using *Configurator.setlevel(*) and the second image
is the actual class where actual logs are printed.
what i noticed is, when the

[image: image.png]

[image: image.png]


On Wed, Mar 23, 2022 at 10:52 PM Piotr P. Karwasz <pi...@gmail.com>
wrote:

> Hello Arulkumar,
>
> What method are you using to change the logger's level? The
> `Configurator.setLevel` methods are probably the most appropriate
> ones.
> Can you provide a minimal example of code that does not work?
>
> Piotr
>
> On Wed, 23 Mar 2022 at 06:43, Arulkumar Ponnusamy <pa...@gmail.com>
> wrote:
> >
> >  Hi all,
> > I am currently working on upgrading my log4j framework from 1.x to
> > 2.x(latest) and my application is deployed in the wildfly. As part of our
> > application, we provide the provision to change the log level at runtime.
> > Am facing a peculiar issue where the logging is working(changing the log
> > level) with the 2.17.1 version whereas the same is not working with
> 2.17.2.
> > The change of log level works only if you change it via log4j2.properties
> > files.
> >
> > any pointers on solving this would be great help
> > Thanks
> > Arulkumar Ponnusamy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Reg: Needs help on logging issues on log4j2 latest version 2.17.2

Posted by "Piotr P. Karwasz" <pi...@gmail.com>.
Hello Arulkumar,

What method are you using to change the logger's level? The
`Configurator.setLevel` methods are probably the most appropriate
ones.
Can you provide a minimal example of code that does not work?

Piotr

On Wed, 23 Mar 2022 at 06:43, Arulkumar Ponnusamy <pa...@gmail.com> wrote:
>
>  Hi all,
> I am currently working on upgrading my log4j framework from 1.x to
> 2.x(latest) and my application is deployed in the wildfly. As part of our
> application, we provide the provision to change the log level at runtime.
> Am facing a peculiar issue where the logging is working(changing the log
> level) with the 2.17.1 version whereas the same is not working with 2.17.2.
> The change of log level works only if you change it via log4j2.properties
> files.
>
> any pointers on solving this would be great help
> Thanks
> Arulkumar Ponnusamy

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org