當(dāng)前位置:
首頁(yè) >
前端技术
> javascript
>内容正文
javascript
Bug整理——阿里Ons高版本引入后Spring项目不打印日志问题
生活随笔
收集整理的這篇文章主要介紹了
Bug整理——阿里Ons高版本引入后Spring项目不打印日志问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
報(bào)錯(cuò)信息
2018-07-06 18:48:44,346 main INFO Log4j appears to be running in a Servlet environment, but there's no log4j-web module available. If you want better web container support, please add the log4j-web JAR to your web archive or server lib directory. 2018-07-06 18:48:44,447 main WARN No Root logger was configured, creating default ERROR-level Root logger with Console appender從這里的報(bào)錯(cuò)信息之后,所有的logger日志都不會(huì)被打印。
排查后發(fā)現(xiàn)在
com.aliyun.openservices.shade.com.alibaba.rocketmq.client.log.ClientLogger類中有個(gè)方法是產(chǎn)生logger的 private static Logger createLogger(final String loggerName) {String logConfigFilePath = System.getProperty("rocketmq.client.log.configFile", System.getenv("ROCKETMQ_CLIENT_LOG_CONFIGFILE"));Boolean isloadconfig =Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true"));final String log4JResourceFile =System.getProperty("rocketmq.client.log4j.resource.fileName", "log4j_rocketmq_client.xml");final String logbackResourceFile =System.getProperty("rocketmq.client.logback.resource.fileName", "logback_rocketmq_client.xml");final String log4J2ResourceFile =System.getProperty("rocketmq.client.log4j2.resource.fileName", "log4j2_rocketmq_client.xml");String clientLogRoot = System.getProperty(CLIENT_LOG_ROOT, System.getProperty("user.home") + "/logs/rocketmqlogs");System.setProperty("client.logRoot", clientLogRoot);String clientLogLevel = System.getProperty(CLIENT_LOG_LEVEL, "INFO");System.setProperty("client.logLevel", clientLogLevel);String clientLogMaxIndex = System.getProperty(CLIENT_LOG_MAXINDEX, "10");System.setProperty("client.logFileMaxIndex", clientLogMaxIndex);if (isloadconfig) {try {ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();Class classType = iLoggerFactory.getClass();if (classType.getName().equals("org.slf4j.impl.Log4jLoggerFactory")) {Class<?> domconfigurator;Object domconfiguratorobj;domconfigurator = Class.forName("org.apache.log4j.xml.DOMConfigurator");domconfiguratorobj = domconfigurator.newInstance();if (null == logConfigFilePath) {Method configure = domconfiguratorobj.getClass().getMethod("configure", URL.class);URL url = ClientLogger.class.getClassLoader().getResource(log4JResourceFile);configure.invoke(domconfiguratorobj, url);} else {Method configure = domconfiguratorobj.getClass().getMethod("configure", String.class);configure.invoke(domconfiguratorobj, logConfigFilePath);}} else if (classType.getName().equals("ch.qos.logback.classic.LoggerContext")) {Class<?> joranConfigurator;Class<?> context = Class.forName("ch.qos.logback.core.Context");Object joranConfiguratoroObj;joranConfigurator = Class.forName("ch.qos.logback.classic.joran.JoranConfigurator");joranConfiguratoroObj = joranConfigurator.newInstance();Method setContext = joranConfiguratoroObj.getClass().getMethod("setContext", context);setContext.invoke(joranConfiguratoroObj, iLoggerFactory);if (null == logConfigFilePath) {URL url = ClientLogger.class.getClassLoader().getResource(logbackResourceFile);Method doConfigure =joranConfiguratoroObj.getClass().getMethod("doConfigure", URL.class);doConfigure.invoke(joranConfiguratoroObj, url);} else {Method doConfigure =joranConfiguratoroObj.getClass().getMethod("doConfigure", String.class);doConfigure.invoke(joranConfiguratoroObj, logConfigFilePath);}} else if (classType.getName().equals("org.apache.logging.slf4j.Log4jLoggerFactory")) {Class<?> joranConfigurator = Class.forName("org.apache.logging.log4j.core.config.Configurator");Method initialize = joranConfigurator.getDeclaredMethod("initialize", String.class, String.class);if (null == logConfigFilePath) {initialize.invoke(joranConfigurator, "log4j2", log4J2ResourceFile);} else {initialize.invoke(joranConfigurator, "log4j2", logConfigFilePath);}}} catch (Exception e) {System.err.println(e);}}return LoggerFactory.getLogger(LoggerName.CLIENT_LOGGER_NAME);}主要是這一行:
Boolean isloadconfig =Boolean.parseBoolean(System.getProperty("rocketmq.client.log.loadconfig", "true"));所以在代碼中加上 System.setProperty("rocketmq.client.log.loadconfig","false");即可總結(jié)
以上是生活随笔為你收集整理的Bug整理——阿里Ons高版本引入后Spring项目不打印日志问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Bug整理——Spring boot 执
- 下一篇: 接口幂等性的设计之————redis分布