static final String OPERATION_NAME = "set-root-logger";
public void execute(OperationContext context, ModelNode operation) {
final String level = operation.require(CommonAttributes.LEVEL).asString();
final ModelNode handlers = operation.get(CommonAttributes.HANDLERS);
final ModelNode subModel = context.readModelForUpdate(PathAddress.EMPTY_ADDRESS);
subModel.get(CommonAttributes.ROOT_LOGGER, CommonAttributes.LEVEL).set(level);
subModel.get(CommonAttributes.ROOT_LOGGER, CommonAttributes.HANDLERS).set(handlers);
if (context.getType() == OperationContext.Type.SERVER) {
context.addStep(new OperationStepHandler() {
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
final ServiceTarget target = context.getServiceTarget();
final ServiceVerificationHandler verificationHandler = new ServiceVerificationHandler();
try {
final RootLoggerService service = new RootLoggerService();
service.setLevel(Level.parse(level));
target.addService(LogServices.ROOT_LOGGER, service)
.addListener(verificationHandler)
.setInitialMode(ServiceController.Mode.ACTIVE)
.install();
} catch (Throwable t) {
throw new OperationFailedException(new ModelNode().set(t.getLocalizedMessage()));
}
Collection<ServiceController<?>> loggerControllers = null;
try {
// install logger handler services
if (handlers.getType() != ModelType.UNDEFINED) {
loggerControllers = LogServices.installLoggerHandlers(target, "", handlers, verificationHandler);
}
} catch (Throwable t) {
throw new OperationFailedException(new ModelNode().set(t.getLocalizedMessage()));
}
context.addStep(verificationHandler, OperationContext.Stage.VERIFY);
if (context.completeStep() == OperationContext.ResultAction.ROLLBACK) {