动态调整log4j2日志等级

public Map chgLogLevel() {

Map retMap = new HashMap();

String qrykey= request.getParameter("authKey");

String logLevel= request.getParameter("level");

if(CommonUtil.wsgAuth(qrykey))

{

    LoggerContext loggerContext = LoggerContext.getContext(false);

    LoggerConfig loggerConfig = loggerContext.getConfiguration().getRootLogger();

LOGGER.info("现有日志级别:"+loggerConfig.getLevel());

LOGGER.info("目标日志级别:"+logLevel);

Level level = Level.toLevel(logLevel);

Configurator.setRootLevel(level);

LOGGER.info("调整后日志级别:"+ loggerConfig.getLevel());

retMap.put("retCode", "0");

retMap.put("retMsg", "日志等级修改完成");

}else{

retMap.put("retCode", "11111");

retMap.put("retMsg", "权限校验失败");

}

return retMap;

}

你可能感兴趣的:(log4j2)