logback提供自定义属性接口:
PropertyDefiner:getPropertyValue()
记一笔:GetIpCustomProperty
public String getPropertyValue() { try { InetAddress address = InetAddress.getLocalHost(); return address.getHostAddress(); } catch (UnknownHostException e) { e.printStackTrace(); } return null; }
GetPortCustomProperty==静态无请求获取服务端口号
public String getTomcatPortValue() { try { List<MBeanServer> serverList = MBeanServerFactory .findMBeanServer(null); for (MBeanServer server : serverList) { Set<ObjectName> names = new HashSet<ObjectName>(); names.addAll(server.queryNames(new ObjectName( "Catalina:type=Connector,*"), null)); Iterator<ObjectName> it = names.iterator(); while (it.hasNext()) { ObjectName oname = (ObjectName) it.next(); String pvalue = (String) server.getAttribute(oname, "protocol"); if (StringUtils.equals("HTTP/1.1", pvalue)) { return ObjectUtils.toString(server.getAttribute(oname, "port")); } } } } catch (Exception e) { LOGGER.error("获取port失败,影响logback的文件拼接", e); } return StringUtils.EMPTY; }
GetHomeCustomProperty
public String getPropertyValue() { String jettyPath = System.getProperty("jetty.home"); String catalinaPath = System.getProperty( "catalina.home"); String path = StringUtils.defaultString(jettyPath, catalinaPath); if(StringUtils.isBlank(path)) { return defaultPath; } File file = new File(path); if(file.exists()){ File parentFile = file.getParentFile(); return (parentFile != null? parentFile.getPath(): file.getPath()) +File.separator+ defaultPath; } return defaultPath; }
然后在logback.xml配置文件中,定义自定义标签define name代表标签,class指向处理的类。在初始化时调用getPropertyValue()
相关推荐
赠送jar包:logback-classic-1.2.3.jar; 赠送原API文档:logback-classic-1.2.3-javadoc.jar; 赠送源代码:logback-classic-1.2.3-sources.jar; 包含翻译后的API文档:logback-classic-1.2.3-javadoc-API文档-...
赠送jar包:logback-classic-1.2.10.jar; 赠送原API文档:logback-classic-1.2.10-javadoc.jar; 赠送源代码:logback-classic-1.2.10-sources.jar; 赠送Maven依赖信息文件:logback-classic-1.2.10.pom; 包含...
赠送jar包:logback-classic-1.2.6.jar; 赠送原API文档:logback-classic-1.2.6-javadoc.jar; 赠送源代码:logback-classic-1.2.6-sources.jar; 赠送Maven依赖信息文件:logback-classic-1.2.6.pom; 包含翻译后...
赠送jar包:logback-classic-1.2.3.jar; 赠送原API文档:logback-classic-1.2.3-javadoc.jar; 赠送源代码:logback-classic-1.2.3-sources.jar; 赠送Maven依赖信息文件:logback-classic-1.2.3.pom; 包含翻译后...
赠送jar包:logback-core-1.2.3.jar; 赠送原API文档:logback-core-1.2.3-javadoc.jar; 赠送源代码:logback-core-1.2.3-sources.jar; 赠送Maven依赖信息文件:logback-core-1.2.3.pom; 包含翻译后的API文档:...
赠送jar包:logback-classic-1.2.10.jar; 赠送原API文档:logback-classic-1.2.10-javadoc.jar; 赠送源代码:logback-classic-1.2.10-sources.jar; 赠送Maven依赖信息文件:logback-classic-1.2.10.pom; 包含...
赠送jar包:logback-core-1.2.3.jar; 赠送原API文档:logback-core-1.2.3-javadoc.jar; 赠送源代码:logback-core-1.2.3-sources.jar; 包含翻译后的API文档:logback-core-1.2.3-javadoc-API文档-中文(简体)-...
赠送jar包:logback-core-1.2.10.jar; 赠送原API文档:logback-core-1.2.10-javadoc.jar; 赠送源代码:logback-core-1.2.10-sources.jar; 赠送Maven依赖信息文件:logback-core-1.2.10.pom; 包含翻译后的API文档...
赠送jar包:logback-core-1.2.10.jar; 赠送原API文档:logback-core-1.2.10-javadoc.jar; 赠送源代码:logback-core-1.2.10-sources.jar; 赠送Maven依赖信息文件:logback-core-1.2.10.pom; 包含翻译后的API文档...
赠送jar包:logback-core-1.2.6.jar; 赠送原API文档:logback-core-1.2.6-javadoc.jar; 赠送源代码:logback-core-1.2.6-sources.jar; 赠送Maven依赖信息文件:logback-core-1.2.6.pom; 包含翻译后的API文档:...
logback-cfca-jdk1.6-3.1.0.0.jar
logback-classic-1.2.11.jar
logback-classic-1.2.3.jar
logback-core-1.2.11.jar
logback-classic-1.1.2.jar 资源共享,有需要其他jar包的可以在评论留言,看到后我会陆续上传。
打包找不到 logback-classic问题 COULD NOT FIND logback-classic:logback-classic-1.1.3 解压后将jar包与pom文件都放在.m2\repository指定路径下
logback与spring集成的文件,从官网上找的。上传的文件包括源文件和jar包,以下是连接: https://github.com/qos-ch/logback-extensions/wiki/Spring ...
9. 集成测试:logback-test.xml配置文件可以用于单元测试和集成测试,确保在开发阶段就能获取到合适的日志信息。 10. 社区活跃:作为log4j的升级版,logback有着活跃的开发者社区和持续的维护更新,确保了框架的...
logback-core-1.2.9.jar
包含logback所需:logback-classic-1.1.7.jar、logback-classic-1.1.7-sources.jar、logback-core-1.1.7.jar、logback-core-1.1.7-sources.jar、slf4j-api-1.7.21.jar、slf4j-api-1.7.21-sources.jar