{"id":1828,"date":"2016-12-27T09:45:04","date_gmt":"2016-12-27T01:45:04","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=1828"},"modified":"2026-08-18T12:09:36","modified_gmt":"2026-08-18T04:09:36","slug":"%e6%97%a5%e5%bf%97%e8%be%93%e5%87%ba%e6%a1%86%e6%9e%b6log4j%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=1828","title":{"rendered":"\u65e5\u5fd7\u8f93\u51fa\u6846\u67b6Log4j\u4f7f\u7528"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">Log4j<\/strong> \u662f Apache \u7684\u5f00\u6e90\u65e5\u5fd7\u9879\u76ee\u3002\u7528\u5b83\u53ef\u4ee5\u628a\u65e5\u5fd7\u6253\u5230\u63a7\u5236\u53f0\u3001\u6587\u4ef6\u7b49\u76ee\u7684\u5730\uff0c\u63a7\u5236\u6bcf\u6761\u65e5\u5fd7\u7684\u683c\u5f0f\uff0c\u5e76\u901a\u8fc7\u7ea7\u522b\u66f4\u7ec6\u5730\u63a7\u5236\u751f\u6210\u8fc7\u7a0b\u3002\u8fd9\u4e9b\u90fd\u53ef\u4ee5\u5199\u5728\u914d\u7f6e\u6587\u4ef6\u91cc\uff0c\u4e0d\u5fc5\u6539\u5e94\u7528\u4ee3\u7801\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u901a\u8fc7\u5176\u5b83\u8bed\u8a00\u63a5\u53e3\uff0cC\u3001C++\u3001.Net\u3001PL\/SQL \u4e5f\u80fd\u7528 Log4j\uff0c\u8bed\u6cd5\u548c Java \u91cc\u4e00\u6837\uff0c\u65b9\u4fbf\u591a\u8bed\u8a00\u5206\u5e03\u5f0f\u7cfb\u7edf\u5171\u7528\u4e00\u5957\u65e5\u5fd7\u7ec4\u4ef6\u3002\u501f\u52a9\u7b2c\u4e09\u65b9\u6269\u5c55\uff0c\u8fd8\u53ef\u4ee5\u63a5\u5230 J2EE\u3001JINI \u751a\u81f3 SNMP \u5e94\u7528\u91cc\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u4e09\u4e2a\u7ec4\u4ef6<\/h2>\n<p style=\"margin: 1em 0px;\">Log4j \u6709\u4e09\u4e2a\u4e3b\u8981\u7ec4\u4ef6\uff1a<strong style=\"color: #4870ac;\">Loggers<\/strong>\uff08\u8bb0\u5f55\u5668\uff09\u3001<strong style=\"color: #4870ac;\">Appenders<\/strong>\uff08\u8f93\u51fa\u6e90\uff09\u548c <strong style=\"color: #4870ac;\">Layouts<\/strong>\uff08\u5e03\u5c40\uff09\u3002\u53ef\u4ee5\u7b80\u5355\u7406\u89e3\u6210\uff1a\u65e5\u5fd7\u7c7b\u522b\u3001\u65e5\u5fd7\u8981\u8f93\u51fa\u5230\u54ea\u91cc\u3001\u65e5\u5fd7\u4ee5\u4f55\u79cd\u5f62\u5f0f\u8f93\u51fa\u3002\u4e09\u4e2a\u4e00\u8d77\u7528\uff0c\u5c31\u80fd\u5728\u8fd0\u884c\u65f6\u63a7\u5236\u65e5\u5fd7\u7684\u7c7b\u578b\u3001\u7ea7\u522b\u3001\u6837\u5f0f\u548c\u4f4d\u7f6e\u3002<\/p>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u7ec4\u4ef6<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u4f5c\u7528<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u914d\u7f6e\u8981\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Loggers<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7ea7\u522b\u8fc7\u6ee4<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ea\u8f93\u51fa\u4e0d\u4f4e\u4e8e\u8bbe\u5b9a\u7ea7\u522b\u7684\u65e5\u5fd7<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Appenders<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8f93\u51fa\u5230\u54ea<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">log4j.appender.appenderName = className<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">Layouts<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u600e\u4e48\u6392\u7248<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">log4j.appender.appenderName.layout = className<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. Loggers<\/h3>\n<p style=\"margin: 1em 0px;\">\u7ea7\u522b\u5206\u4e94\u6863\uff0c\u987a\u5e8f\u662f <strong style=\"color: #4870ac;\">DEBUG &lt; INFO &lt; WARN &lt; ERROR &lt; FATAL<\/strong>\uff0c\u7528\u6765\u6807\u8fd9\u6761\u65e5\u5fd7\u6709\u591a\u91cd\u8981\u3002\u89c4\u5219\u662f\uff1a\u53ea\u8f93\u51fa\u7ea7\u522b<strong style=\"color: #4870ac;\">\u4e0d\u4f4e\u4e8e<\/strong>\u8bbe\u5b9a\u7ea7\u522b\u7684\u4fe1\u606f\u3002\u4f8b\u5982 Loggers \u8bbe\u6210 INFO\uff0c\u5219 INFO\u3001WARN\u3001ERROR\u3001FATAL \u90fd\u4f1a\u51fa\uff0c\u6bd4 INFO \u4f4e\u7684 DEBUG \u4e0d\u4f1a\u51fa\u3002<\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. Appenders<\/h3>\n<p style=\"margin: 1em 0px;\">\u53ef\u4ee5\u628a\u65e5\u5fd7\u6253\u5230\u63a7\u5236\u53f0\uff08Console\uff09\u3001\u6587\u4ef6\uff08Files\uff09\u7b49\uff0c\u4e5f\u53ef\u4ee5\u6309\u5929\u6570\u6216\u6587\u4ef6\u5927\u5c0f\u6eda\u52a8\u65b0\u6587\u4ef6\uff0c\u6216\u4ee5\u6d41\u7684\u5f62\u5f0f\u53d1\u5230\u522b\u5904\u3002\u5e38\u7528\u7c7b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">org.apache.log4j.ConsoleAppender\uff08\u63a7\u5236\u53f0\uff09\norg.apache.log4j.FileAppender\uff08\u6587\u4ef6\uff09\norg.apache.log4j.DailyRollingFileAppender\uff08\u6bcf\u5929\u4ea7\u751f\u4e00\u4e2a\u65e5\u5fd7\u6587\u4ef6\uff09\norg.apache.log4j.RollingFileAppender\uff08\u6587\u4ef6\u5927\u5c0f\u5230\u8fbe\u6307\u5b9a\u5c3a\u5bf8\u7684\u65f6\u5019\u4ea7\u751f\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\uff09\norg.apache.log4j.WriterAppender\uff08\u5c06\u65e5\u5fd7\u4fe1\u606f\u4ee5\u6d41\u683c\u5f0f\u53d1\u9001\u5230\u4efb\u610f\u6307\u5b9a\u7684\u5730\u65b9\uff09<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u914d\u7f6e\u6a21\u5f0f\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">log4j.appender.appenderName = className<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. Layouts<\/h3>\n<p style=\"margin: 1em 0px;\">\u53ef\u4ee5\u5728 Appenders \u540e\u9762\u9644\u52a0 Layouts \u6765\u683c\u5f0f\u5316\u8f93\u51fa\u3002\u5e38\u7528\u7c7b\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">org.apache.log4j.HTMLLayout\uff08\u4ee5HTML\u8868\u683c\u5f62\u5f0f\u5e03\u5c40\uff09\norg.apache.log4j.PatternLayout\uff08\u53ef\u4ee5\u7075\u6d3b\u5730\u6307\u5b9a\u5e03\u5c40\u6a21\u5f0f\uff09\norg.apache.log4j.SimpleLayout\uff08\u5305\u542b\u65e5\u5fd7\u4fe1\u606f\u7684\u7ea7\u522b\u548c\u4fe1\u606f\u5b57\u7b26\u4e32\uff09\norg.apache.log4j.TTCCLayout\uff08\u5305\u542b\u65e5\u5fd7\u4ea7\u751f\u7684\u65f6\u95f4\u3001\u7ebf\u7a0b\u3001\u7c7b\u522b\u7b49\u4fe1\u606f\uff09<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u914d\u7f6e\u6a21\u5f0f\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">log4j.appender.appenderName.layout =className<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u4e00\u822c\u7528\u7b2c\u4e8c\u79cd <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">org.apache.log4j.PatternLayout<\/code>\uff0c\u5728 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">log4j.properties<\/code> \u91cc\u81ea\u5b9a\u4e49\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">log4j.appender.*.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u5360\u4f4d\u7b26\u542b\u4e49\uff1a<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">%p \u8f93\u51fa\u4f18\u5148\u7ea7\uff0c\u5373DEBUG\uff0cINFO\uff0cWARN\uff0cERROR\uff0cFATAL\n%r \u8f93\u51fa\u81ea\u5e94\u7528\u542f\u52a8\u5230\u8f93\u51fa\u8be5log\u4fe1\u606f\u8017\u8d39\u7684\u6beb\u79d2\u6570\n%c \u8f93\u51fa\u6240\u5c5e\u7684\u7c7b\u76ee\uff0c\u901a\u5e38\u5c31\u662f\u6240\u5728\u7c7b\u7684\u5168\u540d\n%t \u8f93\u51fa\u4ea7\u751f\u8be5\u65e5\u5fd7\u4e8b\u4ef6\u7684\u7ebf\u7a0b\u540d\n%n \u8f93\u51fa\u4e00\u4e2a\u56de\u8f66\u6362\u884c\u7b26\uff0cWindows\u5e73\u53f0\u4e3a\u201crn\u201d\uff0cUnix\u5e73\u53f0\u4e3a\u201cn\u201d\n%d \u8f93\u51fa\u65e5\u5fd7\u65f6\u95f4\u70b9\u7684\u65e5\u671f\u6216\u65f6\u95f4\uff0c\u9ed8\u8ba4\u683c\u5f0f\u4e3aISO8601\uff0c\u4e5f\u53ef\u4ee5\u5728\u5176\u540e\u6307\u5b9a\u683c\u5f0f\uff0c\u6bd4\u5982\uff1a%d{yyy MMM dd HH:mm:ss,SSS}\uff0c\u8f93\u51fa\u7c7b\u4f3c\uff1a2002\u5e7410\u670818\u65e5 22\uff1a10\uff1a28\uff0c921\n%l \u8f93\u51fa\u65e5\u5fd7\u4e8b\u4ef6\u7684\u53d1\u751f\u4f4d\u7f6e\uff0c\u5305\u62ec\u7c7b\u76ee\u540d\u3001\u53d1\u751f\u7684\u7ebf\u7a0b\uff0c\u4ee5\u53ca\u5728\u4ee3\u7801\u4e2d\u7684\u884c\u6570\u3002\u4e3e\u4f8b\uff1aTestlog4.main(TestLog4.java:10)<\/code><\/pre>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u4f7f\u7528\u5b9e\u4f8b<\/h2>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">1. \u4e0b\u8f7d log4j.jar<\/h3>\n<p style=\"margin: 1em 0px;\">\u5730\u5740\uff1a<a href=\"http:\/\/logging.apache.org\/log4j\/1.2\/download.html\">http:\/\/logging.apache.org\/log4j\/1.2\/download.html<\/a><\/p>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">2. log4j.properties \u914d\u7f6e\u6587\u4ef6<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">### \u8bbe\u7f6e###\nlog4j.rootLogger = debug,stdout,D,E\n\n### \u8f93\u51fa\u4fe1\u606f\u5230\u63a7\u5236\u62ac ###\nlog4j.appender.stdout = org.apache.log4j.ConsoleAppender\nlog4j.appender.stdout.Target = System.out\nlog4j.appender.stdout.layout = org.apache.log4j.PatternLayout\nlog4j.appender.stdout.layout.ConversionPattern = [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n\n\n### \u8f93\u51faDEBUG \u7ea7\u522b\u4ee5\u4e0a\u7684\u65e5\u5fd7\u5230=D:\/\/logs\/debug.log ###\nlog4j.appender.D = org.apache.log4j.DailyRollingFileAppender\nlog4j.appender.D.File = D:\/\/logs\/debug.log\nlog4j.appender.D.Append = true\nlog4j.appender.D.Threshold = DEBUG\nlog4j.appender.D.layout = org.apache.log4j.PatternLayout\nlog4j.appender.D.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n\n\n### \u8f93\u51faERROR \u7ea7\u522b\u4ee5\u4e0a\u7684\u65e5\u5fd7\u5230=D:\/\/logs\/error.log ###\nlog4j.appender.E = org.apache.log4j.DailyRollingFileAppender\nlog4j.appender.E.File =D:\/\/logs\/error.log\nlog4j.appender.E.Append = true\nlog4j.appender.E.Threshold = ERROR\nlog4j.appender.E.layout = org.apache.log4j.PatternLayout\nlog4j.appender.E.layout.ConversionPattern = %-d{yyyy-MM-dd HH:mm:ss}  [ %t:%r ] - [ %p ]  %m%n<\/code><\/pre>\n<h3 style=\"padding: 0px; color: #4870ac; margin: 1.2em 0px 1em; font-size: 1.3em;\">3. \u4ee3\u7801\u4f7f\u7528<\/h3>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">import org.apache.log4j.Logger;\n\npublic class LogTest {\n\n    private static Logger logger = Logger.getLogger(LogTest.class);\n\n    public static void main(String[] args) {\n        \/\/ \u8bb0\u5f55debug\u7ea7\u522b\u7684\u4fe1\u606f\n        logger.debug(\"This is debug message.\");\n        \/\/ \u8bb0\u5f55info\u7ea7\u522b\u7684\u4fe1\u606f\n        logger.info(\"This is info message.\");\n        \/\/ \u8bb0\u5f55error\u7ea7\u522b\u7684\u4fe1\u606f\n        logger.error(\"This is error message.\");\n    }\n}<\/code><\/pre>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1aLog4j \u7528 Logger \u5b9a\u7ea7\u522b\u3001Appender \u5b9a\u53bb\u5411\u3001Layout \u5b9a\u683c\u5f0f\uff0c\u6539 log4j.properties \u5c31\u80fd\u6362\u8f93\u51fa\uff0c\u4e0d\u5fc5\u52a8\u4e1a\u52a1\u4ee3\u7801\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Log4j \u662f Apache \u7684\u5f00\u6e90\u65e5\u5fd7\u9879\u76ee\u3002\u7528\u5b83\u53ef\u4ee5\u628a\u65e5\u5fd7\u6253\u5230\u63a7\u5236\u53f0\u3001\u6587\u4ef6\u7b49\u76ee\u7684\u5730\uff0c\u63a7\u5236\u6bcf\u6761\u65e5\u5fd7\u7684\u683c\u5f0f\uff0c\u5e76\u901a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[86],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1828"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1828"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1828\/revisions"}],"predecessor-version":[{"id":1831,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/1828\/revisions\/1831"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}