{"id":315,"date":"2022-04-08T23:16:41","date_gmt":"2022-04-08T15:16:41","guid":{"rendered":"https:\/\/blog.lijiajia.top\/?p=315"},"modified":"2026-06-19T21:38:17","modified_gmt":"2026-06-19T13:38:17","slug":"spring5%e6%a1%86%e6%9e%b6%e5%ad%a6%e4%b9%a0%ef%bc%9a%e6%96%b0%e5%8a%9f%e8%83%bd%e4%ba%8c%e5%8d%81%e4%b8%89","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=315","title":{"rendered":"Spring5\u6846\u67b6\u5b66\u4e60\uff1a\u65b0\u529f\u80fd-\u6574\u5408log4j2\u65e5\u5fd7\u6846\u67b6(\u4e8c\u5341\u4e09)"},"content":{"rendered":"<p>\u65b0\u529f\u80fd\u6587\u6863\uff1a<a href=\"https:\/\/cntofu.com\/book\/95\/33-what-new-in-the-spring-framework.md\">https:\/\/cntofu.com\/book\/95\/33-what-new-in-the-spring-framework.md<\/a><\/p>\n<p>1\u3001\u6574\u4e2aSpring5\u6846\u67b6\u7684\u4ee3\u7801\u57fa\u4e8eJava8,\u8fd0\u884c\u65f6\u517c\u5bb9JDK9,\u8bb8\u591a\u4e0d\u5efa\u8bae\u4f7f\u7528\u7684\u7c7b\u548c\u65b9\u6cd5\u5728\u4ee3\u7801\u5e93\u4e2d\u5220\u9664<br \/>\n2\u3001Spring5.0\u6846\u67b6\u81ea\u5e26\u4e86\u901a\u7528\u7684\u65e5\u5fd7\u5c01\u88c5<br \/>\n(1)Spring5\u5df2\u7ecf\u79fb\u9664Log4jConfigListener,\u5b98\u65b9\u5efa\u8bae\u4f7f\u7528Log4j2<br \/>\n(2)Spring5\u6846\u67b6\u6574\u5408Log4j2<\/p>\n<p>\u7b2c\u4e00\u6b65\uff1a\u5f15\u5165jar\u5305<\/p>\n<pre><code class=\"language-markdown\">log4j-api-2.11.2.jar\nlog4j-core-2.11.2.jar\nlog4j-slf4j-impl-2.11.2.jar\nslf4j-api-1.7.30.jar<\/code><\/pre>\n<p>\u7b2c\u4e8c\u6b65\uff1a\u521b\u5efalog4j2.xml\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;!--\u65e5\u5fd7\u7ea7\u522b\u4ee5\u53ca\u4f18\u5148\u7ea7\u6392\u5e8f: OFF &gt; FATAL &gt; ERROR &gt; WARN &gt; INFO &gt; DEBUG &gt; TRACE &gt; ALL --&gt;\n&lt;!--Configuration\u540e\u9762\u7684status\u7528\u4e8e\u8bbe\u7f6elog4j2\u81ea\u8eab\u5185\u90e8\u7684\u4fe1\u606f\u8f93\u51fa\uff0c\u53ef\u4ee5\u4e0d\u8bbe\u7f6e\uff0c\u5f53\u8bbe\u7f6e\u6210trace\u65f6\uff0c\u53ef\u4ee5\u770b\u5230log4j2\u5185\u90e8\u5404\u79cd\u8be6\u7ec6\u8f93\u51fa--&gt;\n&lt;configuration status=&quot;DEBUG&quot;&gt;\n    &lt;!--\u5148\u5b9a\u4e49\u6240\u6709\u7684appender--&gt;\n    &lt;appenders&gt;\n        &lt;!--\u8f93\u51fa\u65e5\u5fd7\u4fe1\u606f\u5230\u63a7\u5236\u53f0--&gt;\n        &lt;console name=&quot;Console&quot; target=&quot;SYSTEM_OUT&quot;&gt;\n            &lt;!--\u63a7\u5236\u65e5\u5fd7\u8f93\u51fa\u7684\u683c\u5f0f--&gt;\n            &lt;PatternLayout pattern=&quot;%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n&quot;\/&gt;\n        &lt;\/console&gt;\n    &lt;\/appenders&gt;\n    &lt;!--\u7136\u540e\u5b9a\u4e49logger\uff0c\u53ea\u6709\u5b9a\u4e49\u4e86logger\u5e76\u5f15\u5165\u7684appender\uff0cappender\u624d\u4f1a\u751f\u6548--&gt;\n    &lt;!--root\uff1a\u7528\u4e8e\u6307\u5b9a\u9879\u76ee\u7684\u6839\u65e5\u5fd7\uff0c\u5982\u679c\u6ca1\u6709\u5355\u72ec\u6307\u5b9aLogger\uff0c\u5219\u4f1a\u4f7f\u7528root\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u65e5\u5fd7\u8f93\u51fa--&gt;\n    &lt;loggers&gt;\n        &lt;root level=&quot;info&quot;&gt;\n            &lt;appender-ref ref=&quot;Console&quot;\/&gt;\n        &lt;\/root&gt;\n    &lt;\/loggers&gt;\n&lt;\/configuration&gt;<\/code><\/pre>\n<p>\u5c31\u53ef\u4ee5\u542f\u7528\u65e5\u5fd7\u4e86\uff0c\u8fd8\u53ef\u4ee5\u624b\u52a8\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-java\">public class TestLog {\n\n    public static final Logger log = LoggerFactory.getLogger(TestLog.class);\n\n    public static void main(String[] args) {\n\n        log.info(&quot;Hello info!&quot;);\n\n        log.warn(&quot;Hello warn!&quot;);\n\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u65b0\u529f\u80fd\u6587\u6863\uff1ahttps:\/\/cntofu.com\/book\/95\/33-what-new-in-the-spr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[125],"tags":[68],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-java-backend","tag-spring"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":2140,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/2140"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}