I am currently running WildFly 23, and I want to force a certain log level when my application is deployed in it. Meaning that, if someone were to go into the standalone.xml file and change the log level to something else, the application would detect it and change it back to the level I want.
The detecting part is easy, but I'm having trouble setting it back. I work with slf4j and it does not have a setLevel method. I could do it by importing the log4j dependency and change the level through log4j's setLevel method, but I do not want to import specific logger library dependencies, I'd like to stay only with slf4j.
I could also do it through jboss-cli commands, but that requires running a separate script, which could be manually modified as well, so I wanted to do it programatically from inside the code.
I have searched a lot for a way to do this but have not found anything that could help me out. Does anyone have any idea on how one would go about doing that, if it is even possible?
Thank you very much!
Sorry for posting an answer so long after the question, I actually managed to solve this a while ago but forgot to post my solution here.
As James said in his answer, you should probably avoid doing this, but in my case I had to do it because of regulatory rules where the system could NEVER execute without the logs running. But we also couldn't not execute the system if logs were off because it's a critical system that should never be offline. This might not be the best solution out there, but if you're in the same boat, here's how I did it:
First of all, you'll need the Wildfly Client dependency in your project:
Then you can use the Wildfly Client to execute jboss-cli commands:
I hope this helps someone out there!