• 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Log4j2 Logger's level

 
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: 2722
354
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • 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.

 
What's that smell? I think this tiny ad may have stepped in something.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!