{"id":80691,"date":"2026-03-05T19:27:12","date_gmt":"2026-03-05T11:27:12","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/80691.html"},"modified":"2026-03-05T19:27:12","modified_gmt":"2026-03-05T11:27:12","slug":"log4j-%e6%97%a5%e5%bf%97%e6%a1%86%e6%9e%b6%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e5%b0%81%e7%a5%9e%e7%9a%84%e9%80%9a%e5%85%b3%e7%a7%98%e7%b1%8d","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/80691.html","title":{"rendered":"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d"},"content":{"rendered":"<h2><\/h2>\n<h2>\u544a\u522bSystem.out.println&#xff01;Log4j\u65e5\u5fd7\u6846\u67b6\u901a\u5173\u79d8\u7c4d&#xff0c;\u4ece\u5165\u95e8\u5230\u5c01\u795e &#x1f680;<\/h2>\n<p>\u524d\u8a00&#xff1a;\u8fd8\u5728\u9760System.out.println\u6253\u65e5\u5fd7\u6392\u9519&#xff1f;\u7ebf\u4e0a\u73af\u5883\u65e5\u5fd7\u5237\u5c4f\u627e\u4e0d\u5230\u5173\u952e\u4fe1\u606f&#xff1f;\u65e5\u5fd7\u6587\u4ef6\u5927\u5230\u7206\u76d8&#xff1f;\u4eca\u5929\u8fd9\u7bc7\u6587&#xff0c;\u5e26\u4f60\u628aLog4j\u73a9\u51fa\u82b1&#xff0c;\u4ece\u201c\u65e5\u5fd7\u5c0f\u767d\u201d\u79d2\u53d8\u201c\u65e5\u5fd7\u5927\u795e\u201d&#xff0c;\u8ba9\u65e5\u5fd7\u6210\u4e3a\u4f60\u6392\u67e5\u95ee\u9898\u7684\u795e\u961f\u53cb&#xff01;<\/p>\n<h3>\u4e00\u3001\u5148\u5410\u69fd&#xff1a;\u4e3a\u5565System.out.println\u662f\u201c\u65e5\u5fd7\u523a\u5ba2\u201d&#xff1f;<\/h3>\n<p>\u54b1\u5148\u804a\u804a\u8e29\u5751\u7ecf\u5386&#xff1a;\u521a\u5165\u884c\u65f6&#xff0c;\u6211\u6ee1\u5c4f\u5199System.out.println(&#034;\u7528\u6237\u767b\u5f55\u4e86&#034;)&#xff0c;\u6d4b\u8bd5\u73af\u5883\u770b\u7740\u633a\u9999&#xff0c;\u4e00\u5230\u751f\u4ea7\u73af\u5883\u76f4\u63a5\u201c\u7ffb\u8f66\u201d\u2014\u2014<\/p>\n<ul>\n<li>\n<p>\u65e5\u5fd7\u5168\u5806\u63a7\u5236\u53f0&#xff0c;\u8fd0\u7ef4\u5c0f\u54e5\u8ffd\u7740\u6211\u9a82&#xff1a;\u201c\u63a7\u5236\u53f0\u5361\u7206\u4e86&#xff01;\u201d<\/p>\n<\/li>\n<li>\n<p>\u60f3\u67e5\u6628\u5929\u7684\u5f02\u5e38&#xff1f;\u6ca1\u5907\u4efd&#xff0c;\u65e5\u5fd7\u65e9\u6ca1\u4e86&#x1f625;<\/p>\n<\/li>\n<li>\n<p>\u8c03\u8bd5\u4fe1\u606f\u548c\u62a5\u9519\u4fe1\u606f\u6df7\u5728\u4e00\u8d77&#xff0c;\u7ffb\u534a\u5929\u627e\u4e0d\u5230\u5173\u952e\u5185\u5bb9<\/p>\n<\/li>\n<\/ul>\n<p>\u76f4\u5230\u6211\u7528\u4e0a\u4e86Log4j&#xff0c;\u624d\u53d1\u73b0&#xff1a;\u539f\u6765\u65e5\u5fd7\u8fd8\u80fd\u8fd9\u4e48\u73a9&#xff01;\u591a\u8f93\u51fa\u76ee\u7684\u5730\u3001\u81ea\u52a8\u5206\u5272\u6587\u4ef6\u3001\u6309\u7ea7\u522b\u8fc7\u6ee4\u2026 \u7b80\u76f4\u662f\u6253\u5f00\u4e86\u65b0\u4e16\u754c\u7684\u5927\u95e8\u3002<\/p>\n<h3>\u4e8c\u3001\u65e5\u5fd7\u6846\u67b6\u754c\u7684\u201c\u8001\u5927\u54e5\u201d&#xff1a;Log4j\u51ed\u5565\u8fd9\u4e48\u9999&#xff1f;<\/h3>\n<p>\u5148\u770b\u4e00\u7ec4\u7075\u9b42\u5bf9\u6bd4&#xff0c;\u61c2\u7684\u90fd\u61c2&#xff1a;<\/p>\n<table>\n<tr>\n<p>\u5bf9\u6bd4\u7ef4\u5ea6<\/p>\n<p>System.out.println&#xff08;\u65e5\u5fd7\u523a\u5ba2&#xff09;<\/p>\n<p>Log4j&#xff08;\u65e5\u5fd7\u738b\u8005&#xff09;<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6027\u80fd<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u540c\u6b65\u963b\u585e&#xff0c;\u9ad8\u5e76\u53d1\u76f4\u63a5\u5361\u6210PPT<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5f02\u6b65\u8f93\u51fa&#xff0c;\u9ad8\u5e76\u53d1\u4e5f\u80fd\u4e1d\u6ed1\u8fd0\u884c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u76ee\u7684\u5730<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53ea\u6709\u63a7\u5236\u53f0&#xff0c;\u60f3\u5b58\u6587\u4ef6&#xff1f;\u81ea\u5df1\u5199\u4ee3\u7801<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u63a7\u5236\u53f0\u3001\u6587\u4ef6\u3001\u6570\u636e\u5e93\u3001\u6d88\u606f\u961f\u5217\u2026 \u60f3\u8f93\u54ea\u5c31\u8f93\u54ea<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u683c\u5f0f<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5149\u79c3\u79c3\u7684\u6587\u5b57&#xff0c;\u8fde\u65f6\u95f4\u90fd\u6ca1\u6709<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u81ea\u5e26\u65f6\u95f4\u3001\u7ebf\u7a0b\u3001\u7c7b\u540d\u3001\u884c\u53f7&#xff0c;\u7ed3\u6784\u5316\u4e00\u76ee\u4e86\u7136<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6301\u4e45\u5316<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u624b\u52a8\u5907\u4efd&#xff1f;\u4e0d\u5b58\u5728\u7684<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6309\u5927\u5c0f\/\u65f6\u95f4\u81ea\u52a8\u5206\u5272&#xff0c;\u5f52\u6863\u8d3c\u7701\u5fc3<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7ea7\u522b\u63a7\u5236<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6240\u6709\u65e5\u5fd7\u5168\u8f93\u51fa&#xff0c;\u60f3\u5173\u90fd\u5173\u4e0d\u6389<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u60f3\u8f93\u5565\u7ea7\u522b\u8f93\u5565\u7ea7\u522b&#xff0c;\u751f\u4ea7\u73af\u5883\u4e00\u952e\u5c4f\u853d\u8c03\u8bd5\u65e5\u5fd7<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e09\u3001Log4j\u6838\u5fc3\u4e09\u5251\u5ba2&#xff1a;Logger\u3001Appender\u3001Layout &#x1f93a;<\/h3>\n<p>Log4j\u7684\u6838\u5fc3\u5c31\u4ee8\u7ec4\u4ef6&#xff0c;\u62df\u4eba\u5316\u7406\u89e3\u8d85\u7b80\u5355&#xff1a;<\/p>\n<h4>3.1 Logger&#xff08;\u65e5\u5fd7\u8bb0\u5f55\u5458&#xff09;<\/h4>\n<p>\u76f8\u5f53\u4e8e\u516c\u53f8\u91cc\u201c\u6536\u96c6\u4fe1\u606f\u7684\u524d\u53f0\u201d&#xff0c;\u7a0b\u5e8f\u91cc\u76f4\u63a5\u8c03\u7528\u5b83\u8bb0\u5f55\u65e5\u5fd7\u3002<\/p>\n<ul>\n<li>\n<p>\u547d\u540d\u6280\u5de7&#xff1a;\u7528\u5f53\u524d\u7c7b\u7684\u5168\u9650\u5b9a\u540d&#xff08;\u6bd4\u5982com.demo.UserService&#xff09;&#xff0c;\u65e5\u5fd7\u51fa\u95ee\u9898\u80fd\u7cbe\u51c6\u5b9a\u4f4d\u5230\u7c7b&#xff01;<\/p>\n<\/li>\n<li>\n<p>\u83b7\u53d6\u65b9\u5f0f&#xff1a;Logger logger &#061; Logger.getLogger(\u5f53\u524d\u7c7b.class);&#xff08;\u540e\u9762\u6709\u5077\u61d2\u6280\u5de7&#xff0c;\u4e0d\u7528\u6bcf\u6b21\u5199&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h4>3.2 Appender&#xff08;\u65e5\u5fd7\u5feb\u9012\u5458&#xff09;<\/h4>\n<p>\u8d1f\u8d23\u628a\u65e5\u5fd7\u201c\u9001\u201d\u5230\u6307\u5b9a\u5730\u65b9&#xff0c;\u4e00\u4e2a\u8bb0\u5f55\u5458\u53ef\u4ee5\u5bf9\u63a5\u591a\u4e2a\u5feb\u9012\u5458&#xff1a;<\/p>\n<ul>\n<li>\n<p>&#x1f5a5;\ufe0f ConsoleAppender&#xff1a;\u9001\u63a7\u5236\u53f0&#xff08;\u6d4b\u8bd5\u7528&#xff09;<\/p>\n<\/li>\n<li>\n<p>&#x1f4c4; FileAppender&#xff1a;\u9001\u666e\u901a\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>&#x1f504; RollingFileAppender&#xff1a;\u6587\u4ef6\u6ee1\u4e86\u81ea\u52a8\u5206\u5272&#xff08;\u751f\u4ea7\u5fc5\u7528&#xff01;&#xff09;<\/p>\n<\/li>\n<li>\n<p>&#x1f4c5; DailyRollingFileAppender&#xff1a;\u6bcf\u5929\u751f\u6210\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6&#xff08;\u67e5\u5386\u53f2\u65e5\u5fd7\u8d85\u65b9\u4fbf&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h4>3.3 Layout&#xff08;\u65e5\u5fd7\u5305\u88c5\u5458&#xff09;<\/h4>\n<p>\u7ed9\u65e5\u5fd7\u201c\u5305\u88c5\u201d\u6210\u597d\u770b\u53c8\u5b9e\u7528\u7684\u683c\u5f0f&#xff0c;\u6bd4\u5982\u5e26\u65f6\u95f4\u3001\u7ea7\u522b\u3001\u7c7b\u540d&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6700\u5e38\u7528\u7684PatternLayout&#xff1a;\u81ea\u5b9a\u4e49\u6a21\u677f&#xff0c;\u6bd4\u5982%d{yyyy-MM-dd HH:mm:ss} [%5p] %c{1} &#8211; %m%n&#xff0c;\u8f93\u51fa\u6548\u679c&#xff1a;<\/p>\n<\/li>\n<\/ul>\n<p>2024-05-20 16:30:00 [ INFO] UserService &#8211; \u7528\u6237admin\u767b\u5f55\u6210\u529f<\/p>\n<h3>\u56db\u3001\u65e5\u5fd7\u7ea7\u522b&#xff1a;\u522b\u778e\u6253&#xff01;\u4e0d\u540c\u573a\u666f\u7528\u5bf9\u7ea7\u522b &#x1f6a8;<\/h3>\n<p>Log4j\u7684\u65e5\u5fd7\u7ea7\u522b\u6709\u4f18\u5148\u7ea7&#xff08;\u4ece\u9ad8\u5230\u4f4e&#xff09;&#xff0c;\u8bb0\u597d\u8fd9\u4e2a\u53e3\u8bc0&#xff1a;FATAL\u8eba\u5e73&#xff0c;ERROR\u62a5\u9519&#xff0c;WARN\u63d0\u9192&#xff0c;INFO\u65e5\u5e38&#xff0c;DEBUG\u8c03\u8bd5&#xff0c;TRACE\u5228\u6839<\/p>\n<table>\n<tr>\n<p>\u7ea7\u522b<\/p>\n<p>\u9002\u7528\u573a\u666f&#xff08;\u4eba\u8bdd\u7248&#xff09;<\/p>\n<p>\u4e3e\u4f8b<\/p>\n<\/tr>\n<tbody>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>FATAL<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7a0b\u5e8f\u76f4\u63a5\u8eba\u5e73&#xff0c;\u6ca1\u6cd5\u8dd1\u4e86&#xff08;\u81f4\u547d\u9519\u8bef&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\u3001\u6838\u5fc3\u914d\u7f6e\u4e22\u4e86<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>ERROR<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u51fa\u95ee\u9898\u4e86&#xff0c;\u4f46\u7a0b\u5e8f\u8fd8\u80fd\u51d1\u6d3b\u7528<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5355\u4e2a\u63a5\u53e3\u8c03\u7528\u5931\u8d25\u3001\u6570\u636e\u67e5\u8be2\u62a5\u9519<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>WARN<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4e0d\u592a\u5bf9&#xff0c;\u4f46\u4e0d\u4e00\u5b9a\u62a5\u9519&#xff08;\u6e29\u99a8\u63d0\u793a&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53c2\u6570\u4e0d\u5408\u6cd5\u3001\u7f13\u5b58\u8fc7\u671f\u3001\u7528\u6237\u5bc6\u7801\u590d\u6742\u5ea6\u592a\u4f4e<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>INFO<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6b63\u5e38\u8fd0\u884c\u7684\u5173\u952e\u8282\u70b9&#xff08;\u7559\u75d5\u7528&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u7a0b\u5e8f\u542f\u52a8\u5b8c\u6210\u3001\u7528\u6237\u767b\u5f55\u6210\u529f\u3001\u8ba2\u5355\u63d0\u4ea4\u5b8c\u6210<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>DEBUG<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u5f00\u53d1\u8c03\u8bd5\u7528&#xff08;\u751f\u4ea7\u73af\u5883\u8981\u5173&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u53d8\u91cf\u503c\u3001\u65b9\u6cd5\u6267\u884c\u6b65\u9aa4\u3001\u63a5\u53e3\u5165\u53c2<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td colspan=\"1\" rowspan=\"1\">\n<p>TRACE<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u6bd4DEBUG\u8fd8\u7ec6&#xff08;\u51e0\u4e4e\u4e0d\u7528&#xff09;<\/p>\n<\/td>\n<td colspan=\"1\" rowspan=\"1\">\n<p>\u4ee3\u7801\u6bcf\u4e00\u6b65\u6267\u884c\u8f68\u8ff9&#xff08;\u6bd4\u5982\u5faa\u73af\u91cc\u7684\u6bcf\u4e00\u6b21\u8fed\u4ee3&#xff09;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&#x1f4a1; \u6838\u5fc3\u89c4\u5219&#xff1a;\u53ea\u8f93\u51fa \u2265 \u5f53\u524d\u7ea7\u522b\u65e5\u5fd7&#xff01;\u6bd4\u5982\u8bbe\u4e3aINFO&#xff0c;DEBUG\/TRACE\u76f4\u63a5\u88ab\u8fc7\u6ee4&#xff0c;\u751f\u4ea7\u73af\u5883\u8d85\u7701\u7a7a\u95f4\u3002<\/p>\n<h3>\u4e94\u3001\u73af\u5883\u642d\u5efa&#xff1a;5\u5206\u949f\u641e\u5b9aLog4j &#x1f6e0;\ufe0f<\/h3>\n<h4>5.1 Maven\u4e00\u952e\u5f15\u5165&#xff08;\u61d2\u4eba\u7248&#xff09;<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"159\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688e1e20e.png\" width=\"471\" \/><\/p>\n<h4>5.2 \u65e0\u914d\u7f6e\u6587\u4ef6&#xff1f;Log4j\u7684\u201c\u9ed8\u8ba4\u813e\u6c14\u201d<\/h4>\n<p>\u6ca1\u914d\u914d\u7f6e\u6587\u4ef6\u65f6&#xff0c;Log4j\u53ea\u8f93\u51faERROR\/FATAL\u7ea7\u522b\u5230\u63a7\u5236\u53f0&#xff0c;\u522b\u8e29\u5751&#xff01;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"296\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688e4aa49.png\" width=\"828\" \/><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c&#xff1a;\u53ea\u6709ERROR\u65e5\u5fd7\u4f1a\u51fa\u6765&#xff0c;DEBUG\u76f4\u63a5\u88ab\u541e&#xff01;<\/p>\n<h3>\u516d\u3001\u914d\u7f6e\u6587\u4ef6\u73a9\u51fa\u82b1&#xff1a;Properties vs XML &#x1f4dd;<\/h3>\n<p>Log4j\u652f\u6301\u4e24\u79cd\u914d\u7f6e\u65b9\u5f0f&#xff0c;\u5c0f\u767d\u9009Properties&#xff0c;\u5927\u4f6c\u9009XML&#xff0c;\u54b1\u90fd\u8bb2&#xff01;<\/p>\n<h4>6.1 Properties&#xff08;\u5c0f\u767d\u53cb\u597d\u6b3e&#xff09;<\/h4>\n<p>\u952e\u503c\u5bf9\u683c\u5f0f&#xff0c;\u7b80\u5355\u7c97\u66b4&#xff0c;\u4e3e\u4e2a\u751f\u4ea7\u5e38\u7528\u7684\u4f8b\u5b50&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"452\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688e759c1.png\" width=\"954\" \/><\/p>\n<h4>6.2 XML&#xff08;\u9ad8\u7aef\u5b9a\u5236\u6b3e&#xff09;<\/h4>\n<p>\u7ed3\u6784\u6e05\u6670&#xff0c;\u9002\u5408\u590d\u6742\u914d\u7f6e&#xff0c;\u6bd4\u5982\u7ed9\u4e0d\u540c\u5305\u914d\u4e0d\u540c\u7ea7\u522b&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"618\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688edceec.png\" width=\"1005\" \/><\/p>\n<h4>6.3 \u5c0f\u6280\u5de7&#xff1a;\u6309\u5305\u914d\u7f6e\u65e5\u5fd7\u7ea7\u522b<\/h4>\n<p>\u6bd4\u5982\u8ba9com.demo.service\u5305\u53ea\u8f93\u51faINFO&#xff0c;\u5176\u4ed6\u5305\u8f93\u51faDEBUG&#xff0c;\u751f\u4ea7\u8d85\u5b9e\u7528&#xff01;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"126\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112711-69a9688f2ba8e.png\" width=\"494\" \/><\/p>\n<h3>\u4e03\u3001\u5077\u61d2\u795e\u5668&#xff1a;SLF4J &#043; Lombok&#064;Slf4j \u2728<\/h3>\n<p>\u8fd8\u5728\u5199Logger logger &#061; Logger.getLogger(XXX.class)&#xff1f;\u592aout\u4e86&#xff01;\u7528&#064;Slf4j\u6ce8\u89e3&#xff0c;\u4e00\u884c\u90fd\u4e0d\u7528\u5199&#xff01;<\/p>\n<h4>7.1 \u5f15\u5165\u4f9d\u8d56<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"368\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112711-69a9688f36b69.png\" width=\"549\" \/><\/p>\n<h4>7.2 \u4ee3\u7801\u76f4\u63a5\u8d77\u98de<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"545\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112711-69a9688f6e9c6.png\" width=\"753\" \/><\/p>\n<p>&#x1f4a1; \u6ce8\u610f&#xff1a;IDEA\/Eclipse\u8981\u88c5Lombok\u63d2\u4ef6&#xff0c;\u4e0d\u7136\u4f1a\u63d0\u793alog\u627e\u4e0d\u5230&#xff08;\u7f16\u8bd1\u4e0d\u5f71\u54cd&#xff0c;\u53ea\u662f\u63d0\u793a&#xff09;\u3002<\/p>\n<h3>\u516b\u3001\u8e29\u5751\u6307\u5357&#xff1a;\u90a3\u4e9b\u5e74\u6211\u4eec\u8e29\u8fc7\u7684Log4j\u5751 &#x1f573;\ufe0f<\/h3>\n<h4>\u57511&#xff1a;\u8b66\u544a\u201cCould not find log4j.properties\u201d<\/h4>\n<p>\u539f\u56e0&#xff1a;\u914d\u7f6e\u6587\u4ef6\u6ca1\u653e\u5bf9\u4f4d\u7f6e&#xff01;<\/p>\n<p>\u89e3\u51b3&#xff1a;\u628alog4j.properties\/xml\u653e\u5230src\/main\/resources&#xff08;Maven\u9879\u76ee&#xff09;\u3002<\/p>\n<h4>\u57512&#xff1a;\u65e5\u5fd7\u5199\u4e0d\u8fdb\u6587\u4ef6<\/h4>\n<p>\u6392\u67e5\u6b65\u9aa4&#xff1a;<\/p>\n<li>\n<p>\u8def\u5f84\u9519\u4e86&#xff1f;\u68c0\u67e5File\u914d\u7f6e&#xff08;\u7edd\u5bf9\u8def\u5f84\/\u76f8\u5bf9\u8def\u5f84&#xff09;&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6ca1\u6743\u9650&#xff1f;\u7ed9\u65e5\u5fd7\u76ee\u5f55\u52a0\u5199\u5165\u6743\u9650&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7ea7\u522b\u592a\u9ad8&#xff1f;\u6bd4\u5982\u8bbe\u4e86INFO&#xff0c;DEBUG\u65e5\u5fd7\u5199\u4e0d\u8fdb\u53bb\u3002<\/p>\n<\/li>\n<h4>\u57513&#xff1a;\u65e5\u5fd7\u91cd\u590d\u8f93\u51fa<\/h4>\n<p>\u539f\u56e0&#xff1a;\u81ea\u5b9a\u4e49Logger\u7684additivity\u9ed8\u8ba4true&#xff0c;\u7ee7\u627f\u4e86\u6839Logger\u7684Appender\u3002<\/p>\n<p>\u89e3\u51b3&#xff1a;log4j.additivity.\u5305\u540d&#061;false&#xff0c;\u7981\u6b62\u7ee7\u627f&#xff01;<\/p>\n<h3>\u4e5d\u3001\u5b9e\u6218\u603b\u7ed3&#xff1a;Log4j\u6700\u4f73\u5b9e\u8df5 &#x1f4d6;<\/h3>\n<li>\n<p>\u751f\u4ea7\u73af\u5883\u522b\u5f00DEBUG\/TRACE&#xff1a;\u65e5\u5fd7\u592a\u591a&#xff0c;\u78c1\u76d8\u625b\u4e0d\u4f4f&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7528\u5360\u4f4d\u7b26\u4ee3\u66ff\u5b57\u7b26\u4e32\u62fc\u63a5&#xff1a;log.info(&#034;\u7528\u6237{}&#034;, name) \u6bd4 log.info(&#034;\u7528\u6237&#034; &#043; name) \u6027\u80fd\u597d&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u654f\u611f\u4fe1\u606f\u522b\u6253\u65e5\u5fd7&#xff1a;\u5bc6\u7801\u3001\u624b\u673a\u53f7\u3001\u8eab\u4efd\u8bc1\u53f7\u8981\u8131\u654f&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u7528\u6eda\u52a8\u65e5\u5fd7&#xff1a;RollingFileAppender\/DailyRollingFileAppender&#xff0c;\u907f\u514d\u6587\u4ef6\u8fc7\u5927&#xff1b;<\/p>\n<\/li>\n<li>\n<p>\u6309\u5305\/\u7c7b\u914d\u7f6e\u7ea7\u522b&#xff1a;\u4e0d\u540c\u6a21\u5757\u65e5\u5fd7\u6309\u9700\u8f93\u51fa&#xff0c;\u6392\u67e5\u66f4\u9ad8\u6548\u3002<\/p>\n<\/li>\n<h3>\u6700\u540e&#xff1a;\u4ece\u201c\u65e5\u5fd7\u5c0f\u767d\u201d\u5230\u201c\u65e5\u5fd7\u5927\u795e\u201d<\/h3>\n<p>Log4j\u4e0d\u662f\u82b1\u91cc\u80e1\u54e8\u7684\u6280\u672f&#xff0c;\u800c\u662f\u80fd\u5b9e\u5b9e\u5728\u5728\u63d0\u9ad8\u6392\u9519\u6548\u7387\u7684\u5de5\u5177\u3002\u544a\u522bSystem.out.println&#xff0c;\u7528Log4j\u628a\u65e5\u5fd7\u73a9\u660e\u767d&#xff0c;\u7ebf\u4e0a\u95ee\u9898\u6392\u67e5\u6548\u7387\u76f4\u63a5\u7ffb\u500d&#xff01;<\/p>\n<p>\u5982\u679c\u8fd9\u7bc7\u6587\u7ae0\u5e2e\u5230\u4f60&#xff0c;\u8bb0\u5f97\u70b9\u8d5e&#043;\u6536\u85cf&#x1f31f;&#xff0c;\u6709\u95ee\u9898\u8bc4\u8bba\u533a\u4ea4\u6d41&#xff0c;\u54b1\u4eec\u4e00\u8d77\u628a\u65e5\u5fd7\u73a9\u51fa\u82b1&#xff5e;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u544a\u522bSystem.out.println&#xff01;Log4j\u65e5\u5fd7\u6846\u67b6\u901a\u5173\u79d8\u7c4d&#xff0c;\u4ece\u5165\u95e8\u5230\u5c01\u795e &#x1f680;\u524d\u8a00&#xff1a;\u8fd8\u5728\u9760System.out.println\u6253\u65e5\u5fd7\u6392\u9519&#xff1f;\u7ebf\u4e0a\u73af\u5883\u65e5\u5fd7\u5237\u5c4f\u627e\u4e0d\u5230\u5173\u952e\u4fe1\u606f&#xff1f;\u65e5\u5fd7\u6587\u4ef6\u5927\u5230\u7206\u76d8&#xff1f;\u4eca\u5929\u8fd9\u7bc7\u6587&#xff0c;\u5e26\u4f60\u628aLog4j\u73a9\u51fa\u82b1&#xff0c;\u4ece\u201c\u65e5\u5fd7\u5c0f\u767d\u201d\u79d2\u53d8\u201c\u65e5\u5fd7\u5927\u795e\u201d&#xff0c;\u8ba9\u65e5\u5fd7\u6210\u4e3a\u4f60\u6392\u67e5\u95ee\u9898\u7684\u795e\u961f\u53cb&#xff01;\u4e00\u3001\u5148\u5410\u69fd&#xff1a;\u4e3a\u5565<\/p>\n","protected":false},"author":2,"featured_media":80684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1835],"topic":[],"class_list":["post-80691","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-1835"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/80691.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u544a\u522bSystem.out.println&#xff01;Log4j\u65e5\u5fd7\u6846\u67b6\u901a\u5173\u79d8\u7c4d&#xff0c;\u4ece\u5165\u95e8\u5230\u5c01\u795e &#x1f680;\u524d\u8a00&#xff1a;\u8fd8\u5728\u9760System.out.println\u6253\u65e5\u5fd7\u6392\u9519&#xff1f;\u7ebf\u4e0a\u73af\u5883\u65e5\u5fd7\u5237\u5c4f\u627e\u4e0d\u5230\u5173\u952e\u4fe1\u606f&#xff1f;\u65e5\u5fd7\u6587\u4ef6\u5927\u5230\u7206\u76d8&#xff1f;\u4eca\u5929\u8fd9\u7bc7\u6587&#xff0c;\u5e26\u4f60\u628aLog4j\u73a9\u51fa\u82b1&#xff0c;\u4ece\u201c\u65e5\u5fd7\u5c0f\u767d\u201d\u79d2\u53d8\u201c\u65e5\u5fd7\u5927\u795e\u201d&#xff0c;\u8ba9\u65e5\u5fd7\u6210\u4e3a\u4f60\u6392\u67e5\u95ee\u9898\u7684\u795e\u961f\u53cb&#xff01;\u4e00\u3001\u5148\u5410\u69fd&#xff1a;\u4e3a\u5565\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/80691.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-03-05T11:27:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688e1e20e.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/80691.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/80691.html\",\"name\":\"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-03-05T11:27:12+00:00\",\"dateModified\":\"2026-03-05T11:27:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/80691.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/80691.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/80691.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/80691.html","og_locale":"zh_CN","og_type":"article","og_title":"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u544a\u522bSystem.out.println&#xff01;Log4j\u65e5\u5fd7\u6846\u67b6\u901a\u5173\u79d8\u7c4d&#xff0c;\u4ece\u5165\u95e8\u5230\u5c01\u795e &#x1f680;\u524d\u8a00&#xff1a;\u8fd8\u5728\u9760System.out.println\u6253\u65e5\u5fd7\u6392\u9519&#xff1f;\u7ebf\u4e0a\u73af\u5883\u65e5\u5fd7\u5237\u5c4f\u627e\u4e0d\u5230\u5173\u952e\u4fe1\u606f&#xff1f;\u65e5\u5fd7\u6587\u4ef6\u5927\u5230\u7206\u76d8&#xff1f;\u4eca\u5929\u8fd9\u7bc7\u6587&#xff0c;\u5e26\u4f60\u628aLog4j\u73a9\u51fa\u82b1&#xff0c;\u4ece\u201c\u65e5\u5fd7\u5c0f\u767d\u201d\u79d2\u53d8\u201c\u65e5\u5fd7\u5927\u795e\u201d&#xff0c;\u8ba9\u65e5\u5fd7\u6210\u4e3a\u4f60\u6392\u67e5\u95ee\u9898\u7684\u795e\u961f\u53cb&#xff01;\u4e00\u3001\u5148\u5410\u69fd&#xff1a;\u4e3a\u5565","og_url":"https:\/\/www.wsisp.com\/helps\/80691.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-03-05T11:27:12+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/03\/20260305112710-69a9688e1e20e.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/80691.html","url":"https:\/\/www.wsisp.com\/helps\/80691.html","name":"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-03-05T11:27:12+00:00","dateModified":"2026-03-05T11:27:12+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/80691.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/80691.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/80691.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Log4j \u65e5\u5fd7\u6846\u67b6\uff1a\u4ece\u5165\u95e8\u5230\u5c01\u795e\u7684\u901a\u5173\u79d8\u7c4d"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/80691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=80691"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/80691\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/80684"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=80691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=80691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=80691"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=80691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}