This content has been marked as final.
Show 3 replies
-
1. Re: Add new loggers in runtime JBOSS EAP 6.4 from Java class
jamezp Jul 24, 2017 5:32 PM (in response to suhaspt)If you want changes at runtime it's best to not use the log4j API's. You can do this with management operations quite easily.
The first question I have though is it really necessary to have this done in Java code? It's a lot easier to do with CLI, the web console or the HTTP management interface.
--
James R. Perkins
-
2. Re: Add new loggers in runtime JBOSS EAP 6.4 from Java class
suhaspt Jul 25, 2017 6:00 AM (in response to jamezp)Hello James,
Thanks for your reply. We have to do this run time without using CLI, the web console or the HTTP management interface. So is there any way, we can enable or disable it from java code at run time.
Thanks,
Suhas Talele
-
3. Re: Add new loggers in runtime JBOSS EAP 6.4 from Java class
jamezp Aug 3, 2017 5:24 PM (in response to suhaspt)The best approach would be to use the management API if you don't want to use one of the other approaches.
try (ModelControllerClient client = ModelControllerClient.Factory.create(InetAddress.getLocalHost(), 9990)) { // Create the address for the org.jboss.as.logging logger final ModelNode address = Operations.createAddress("subsystem", "logging", "logger", "org.jboss.as.logging"); // Create the add operation ModelNode op = Operations.createAddOperation(address); op.get("level").set("DEBUG"); ModelNode result = client.execute(op); if (!Operations.isSuccessfulOutcome(result)) { throw new RuntimeException(Operations.getFailureDescription(result).asString()); } // Change the console to show DEBUG logging final ModelNode consoleHandlerAddress = Operations.createAddress("subsystem", "logging", "console-handler", "CONSOLE"); op = Operations.createWriteAttributeOperation(consoleHandlerAddress, "level", "DEBUG"); result = client.execute(op); if (!Operations.isSuccessfulOutcome(result)) { throw new RuntimeException(Operations.getFailureDescription(result).asString()); } }
--
James R. Perkins