Azhaguvel A
Azhaguvel A

Reputation: 629

How to change the JBoss 7 log configuration through Java?

I have added the custom logger in JBoss-7 standalone.xml and i have mentioned log file name such as /home/sample/sample.log and the log info is printing correctly in that location but My requirement is "Need to change log name dynamically". I can change the log name through JBoss log cli command. "Is this possible to change the log file name via Java Code?".

Upvotes: 0

Views: 250

Answers (1)

Federico Sierra
Federico Sierra

Reputation: 5208

You can use a ModelControllerClient and change everything you can from the CLI.

Eg:

ModelNode op = new ModelNode();
op.get(ClientConstants.OP).set("change-file");
//change MYHANDLER 
op.get(ClientConstants.OP_ADDR).set("/subsystem=logging/periodic-rotating-file-handler=MYHANDLER");

//set new file name as new_file_name.log
ModelNode file = new ModelNode();
file.get("relative-to").set("jboss.server.log.dir");
file.get("path").set("new_file_name.log");
op.get("file").set(file);

ModelControllerClient client = ModelControllerClient.Factory.create("localhost", 9999);
ModelNode result = client.execute(op);

if (result.hasDefined("outcome") && "success".equals(result.get("outcome").asString())) {
    if (result.hasDefined("result")) {
        System.out.println(result.get("result"));
    }
} else if (result.hasDefined("failure-description")) {
    throw new RuntimeException(result.get("failure-description").toString());
} else {
    throw new RuntimeException("Operation not successful; outcome = " + result.get("outcome"));
}

See also:

Upvotes: 1

Related Questions