This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Log4j2 Logger's level  RSS feed

 
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm struggling to find solution on that problem.
Can anybody explain how I could get with java code, the level of my 2 loggers "Console" and "File"

log4j2.png
[Thumbnail for log4j2.png]
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This will certainly help in the answer.
Here the way I set the level of "Console" Appender (Same principle used for File Appender)



Thanks for your help

Chritian
 
Saloon Keeper
Posts: 2476
317
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have expected something like this to work:But sadly ref.getLevel() returns null.
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is actually the issue :-(
My first approach was to use appendersRef instead of Appenders.
Unfortunately with that approach I was  not able to populate the AppenderRefs structure.




Reason why I get back to Appender's Logger instead of AppenderRef's Logger.

In summary:
With the Appender's logger approach, I'm able to populate the Log4j2 data structure and especially the level, but not able to get the level

With the AppenderRef's logger approach, I'm not able to populate the Log4j2 data structure and so not the level, and also not able to get the level

Any help appreciated.

Thanks in advance

Chris
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:
But sadly ref.getLevel() returns null.



The issue in your code was following

     

So Now I have to succeed to populate the AppenderRefs in the Logger by Code...
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To summarize, I would be happy to success to create per java program,  AppenderRef in the Root Logger, then, to set the level, and to read the level

 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any help ? :-)
I'm stuck :-(
Thanks
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic cost me a lot, but finally I got it.
Here ago the solution
Can be easy adapted
All the comments and explanations in the java code..

Have fun, and a thanks would be appreciated :-)

FYI:



 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Little correction.

 
You may have just won ten million dollars! Or, maybe a tiny ad.
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!