Win a copy of Event Streams in Action this week in the Java in General 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to reload a programmed log4j2 configuration

 
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Finally I got it




with

 
Sheriff
Posts: 24594
55
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
You're Welcome
 
Christian Klugesherz
Ranch Hand
Posts: 111
3
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Sure that:

Has no more sense here :-)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!