• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to reload a programmed log4j2 configuration

 
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

There is now some days that I'm spending on java logger: log4j2
I have read several times the doc.
The approach is relatively easy if you decide to work on the basis with an .xml file.
But in case you want to create the configuration and adapt through java, it is a bit more complicated.

Below the code I could manage for now.
I didn't succeed to reconfigure the log level
Each time  depth is stopping on error level

2017-03-15 23:24:27,248 [main] ERROR: This is Logger for 1 Error
2017-03-15 23:24:27,256 [main] ERROR: This is Logger 1 Error

Can you please help to specify how to reload the programmed log4j2 configuration  ?



Many thanks

Christian

 
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
Finally I got it




with

 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting back with the solution, Christian!
 
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
You're Welcome
 
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
Finally I improved.
Basis, is to declare only console in .xml configuration, then to add File appender through programming
This is really useful because the declaration the logger can be kept as "private static final"

AND also to adapt the destination of the log file
Here ago the codes






RESULT

--------- Path of the Log File : D:\Users\kluges1\AppData\Roaming\Pac-Tool
--------- All Declared Appenders {Console=Console, LogFile=LogFile}
Read the Appenders Activate in the Logger
-------- Is Logger Console active --> true
-------- Is Logger File active --> false
--------- Log Level (default in .xml) = INFO
22:18:41.865 ERROR log4j.Log4j2Config - This is Logger for 1 Error
22:18:41.867 INFO  log4j.Log4j2Config - This is Logger for 1 Info
Read the Appenders Activate in the Logger
-------- Is Logger Console active --> true
-------- Is Logger File active --> false
Remove Console Logger
Remove Console Logger
-------- Is Logger Console active --> false
-------- Is Logger File active --> false
Add Console Logger
Add Console Logger
-------- Is Logger Console active --> true
-------- Is Logger File active --> false
Add File Logger
Add LogFile Logger
-------- Is Logger Console active --> true
-------- Is Logger File active --> true
22:18:41.868 ERROR log4j.Log4j2Config - This is Logger 3 Error
22:18:41.868 INFO  log4j.Log4j2Config - This is Logger 3 Info
Before to Set Log Level = INFO
Log Level = TRACE
Log Level = TRACE
22:18:41.869 ERROR log4j.Log4j2Config - This is Logger 4 Error
22:18:41.869 INFO  log4j.Log4j2Config - This is Logger 4 Info
22:18:41.869 DEBUG log4j.Log4j2Config - This is Logger 4 Debug
22:18:41.869 TRACE log4j.Log4j2Config - This is Logger 4 Trace



 
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
Sure that:

Has no more sense here :-)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic