• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Log4j2 Logger's level

 
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 3862
540
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Little correction.

reply
    Bookmark Topic Watch Topic
  • New Topic