Java??????
???????????? ???????[ 2015/7/20 10:19:19 ] ??????????????????? ???????
????ConsoleAppender
????ConsoleAppender??????Appenders??????????????????????????????????????????????????Appender??????????????????н???????á????磬??Log4j??ConsoleAppender?????ò????????????
?????????????Log4j2??????????????????
????<?xml version="1.0" encoding="UTF-8"?>
????<Configuration status="warn" name="MyApp">
????<Appenders>
????<Console name="MyAppender" target="SYSTEM_OUT">
????<PatternLayout pattern="%m%n"/>
????</Console>
????</Appenders>
????<Loggers>
????<Root level="error">
????<AppenderRef ref="MyAppender"/>
????</Root>
????</Loggers>
????</Configuration>
??????????????????????????MyAppender??ConsoleAppender???????PatternLayout?????????????и???????????????????System.out??<Loggers>????????????????е?Loggers?????????á?????????????????????LoggerConfig???????Root??Logger???????????Щ?????????ERROR???????????????????????logger.error()????????????????????????????????????????
????An unexpected error occurred.
??????????????Logback???????????Ч????
????<configuration>
????<appender name="MyAppender" class="ch.qos.Logback.core.ConsoleAppender">
????<encoder>
????<pattern>%m%n</pattern>
????</encoder>
????</appender>
????<root level="error">
????<appender-ref ref="MyAppender" />
????</root>
????</configuration>
????FileAppenders
????FileAppenders????????д??????У??????????????????????????????????????????????м?????????????????????????
??????Log4j?У???????????FileAppender?????????????????????д??????????????????????????д??????????????м?????
????...
????<Appenders>
????<File name="MyFileAppender" fileName="myLog.log" append="true" locking="true">
????<PatternLayout pattern="%m%n"/>
????</File>
????</Appenders>
????...
???????????????????????MyFileAppender??FileAppender???????????????????????????????м?????????
??????????Logback?????????????prudent??????????????????????Prudent????????д?????????????????????????????FileAppender???????Java?????????????д????????????????????
????...
????<appender name="FileAppender" class="ch.qos.Logback.core.FileAppender">
????<file>myLog.log</file>
????<append>true</append>
????<prudent>true</prudent>
????<encoder>
????<pattern>%m%n</pattern>
????</encoder>
????</appender>
????...
????SyslogAppender
????SyslogAppenders??????????????????????????????????syslog?????????????????????Щ??????????????????????????????????????豸????????Χ???????????????????????????syslog??????????豸???з???????????????????????????????磬auth facility??????????????????????й??
????Log4j??Logback?????????SyslogAppenders????Log4j?У????????SyslogAppender?????????syslog???????????????????????Э?顣?????????????????趨????
????...
????<Appenders>
????<Syslog name="SyslogAppender" host="localhost" port="514" protocol="UDP" facility="Auth" />
????</Appenders>
????...
??????Logback?У????????????????Ч????
????...
????<appender name="SyslogAppender" class="ch.qos.Logback.classic.net.SyslogAppender">
????<syslogHost>localhost</syslogHost>
????<port>514</port>
????<facility>Auth</facility>
????</appender>
????...
????????Appender
??????????????????Щ?????????Appenders?????к??????Appender????????????1???????????????ЩAppender????????????1???????磬Log4j?е?RollingFileAppender?????FileAppender??????????????????????????????μ?????????SMTPAppender???????????????????????????FailoverAppender????????????????У?????????????Appender????????л???????Appender???
??????????????????????Appender????????????Log4j Appender?ο????Logback Appender?ο???
????Layouts
????Layouts????????????????????????????????????????????????????HTML??syslog??XML??JSON?????л???????????????Layouts??
???????????java.util.logging??Layouts??????Formatters??
???????磬java.util.logging????????Layouts??SimpleFormatter??XMLFormatter?????????£?ConsoleHandlers???SimpleFormatter???????????????????????????
????Mar 31?? 2015 10:47:51 AM MyClass main
????SEVERE: An exception occurred.
?????????????£?FileHandlers???XMLFormatter?????????????????
????<?xml version="1.0" encoding="UTF-8" standalone="no"?>
????<!DOCTYPE log SYSTEM "logger.dtd">
????<log>
????<record>
????<date>2015-03-31T10:47:51</date>
????<millis>1427903275893</millis>
????<sequence>0</sequence>
????<logger>MyClass</logger>
????<level>SEVERE</level>
????<class>MyClass</class>
????<method>main</method>
????<thread>1</thread>
????<message>An exception occurred.</message>
????</record>
????</log>
????????Layout
???????????????????????Layouts???????á???Java 7?????????????????system property??????SimpleFormatter??
???????磬??Log4j??Logback?г????Layouts??PatternLayout??????????????????????е???Щ??????????????????????????Conversion Pattern???????????????????????????????а?????“?λ??”?????????磬Log4j????PatternLayout????????????????
????<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
????%d{HH:mm:ss.SSS} ?????????????????????????????%level??????????????????%C???????????????????????%t???Logger????????%m??????????????%n????????????????????С?
???????Layouts
?????????java.util.logging?????????????Layout???????Appender??formatter???????ó????????Layout????????У?????????????μ?Handler??????setFormatter????????????logger.AddHandler()??????Handler???Logger???檔?????????????????ConsoleAppender???????XMLFormatter??????????и???????????????????SimpleFormatter??
????Handler ch = new ConsoleHandler();
????ch.setFormatter(new XMLFormatter());
????logger.addHandler(ch);
????????Logger???????????????????????
????<?xml version="1.0" encoding="UTF-8" standalone="no"?>
????<!DOCTYPE log SYSTEM "logger.dtd">
????<log>
????<record>
????<date>2015-03-31T10:47:51</date>
????<millis>1427813271000</millis>
????<sequence>0</sequence>
????<logger>MyClass</logger>
????<level>SEVERE</level>
????<class>MyClass</class>
????<method>main</method>
????<thread>1</thread>
????<message>An exception occurred.</message>
????</record>
??????????????????????????Log4j Layouts?ο????Logback Layouts?ο???
????????????Layouts
?????????Layouts???????????Appender???????????????????Java SE 7?????????????????SimpleLogger????????????????????????????????????????????????????????????HTML????JSON???????????????Layout????????????????
??????????????????java.util.logging?????????Layouts?????????????Jakob Jenkov??Java???????е?Java Logging: Formatters????
???????????
????????????????????????????????????????????????????з???????java.util.logging ???????????????????????????
????SEVERE???????
????WARNING
????INFO
????CONFIG
????FINE
????FINER
????FINEST???????
???????? ???????????????ALL??OFF??ALL????Logger??????????????OFF?????????????
???????????????
???????趨????????Logger???????????Щ?????趨????????????????磬???????????Logger??????Щ????WARNING?????????????
????logger.setLevel(Level.WARNING);
???????Logger?????κ?WARNING???????????????????????????????????????????Logger?????????
????...
????<Loggers>
????<Logger name="MyLogger" level="warning">
????...
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11