差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:log4j2:appenders [2022/04/10 19:08] tony |
java:log4j2:appenders [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 41: | 行 41: | ||
* **appender.logfile.strategy.max**: 即index最大值設定。有max就會有min,min是用來指定最小index,如果你不喜歡從1-3,喜歡從2-3的話,那min就設2。 | * **appender.logfile.strategy.max**: 即index最大值設定。有max就會有min,min是用來指定最小index,如果你不喜歡從1-3,喜歡從2-3的話,那min就設2。 | ||
===== RollingFileAppender with Size, Time and File Count conditions ===== | ===== RollingFileAppender with Size, Time and File Count conditions ===== | ||
- | 這個是基於前一種RollingFileAppender多增加以時間為滾動條件的設定方式。舉例來說,當到隔天的00:00時,我想產生新的log file就會用到這個條件。在log4j1時,要做到這個需求,需要引入另外一個支援TimeAndSizeRollingAppender的library;而在logj2中,則可直接透過TimeBasedTriggeringPolicy做到這個需求。除此之外,如果要做到最大檔案數量控制的話,要多使用Delete action的特性。 | + | 這個是基於前一種RollingFileAppender多增加以時間為滾動條件的設定方式,但由於篇幅較多,請直接參考[[java:log4j2:timeandsizerollingappender|link]]內容。 |
- | <code properties> | + | |
- | appender.logfile.type = RollingFile | + | |
- | appender.logfile.name = LOGFILE | + | |
- | appender.logfile.fileName = ./syslog/log.txt | + | |
- | appender.logfile.filePattern = ./syslog/log.txt.%d{yyyy-MM-dd}.%i | + | |
- | appender.logfile.layout.type = PatternLayout | + | |
- | appender.logfile.layout.pattern = %d{yyyy/MM/dd HH:mm:ss.SSS} %5p[%t] (%F:%M:%L) - %m%n | + | |
- | appender.logfile.policies.type = Policies | + | |
- | appender.logfile.policies.size.type = SizeBasedTriggeringPolicy | + | |
- | appender.logfile.policies.size.size=8000KB | + | |
- | appender.logfile.policies.time.type = TimeBasedTriggeringPolicy | + | |
- | appender.logfile.policies.time.interval = 1 | + | |
- | appender.logfile.policies.time.modulate = true | + | |
- | appender.logfile.strategy.type = DefaultRolloverStrategy | + | |
- | appender.logfile.strategy.fileIndex = nomax | + | |
- | appender.logfile.strategy.action.type = Delete | + | |
- | appender.logfile.strategy.action.basepath = ./syslog/ | + | |
- | appender.logfile.strategy.action.maxDepth = 1 | + | |
- | appender.logfile.strategy.action.ifFileName.type = IfFileName | + | |
- | appender.logfile.strategy.action.ifFileName.glob = log.txt* | + | |
- | appender.logfile.strategy.action.ifFileName.ifAny.type = IfAny | + | |
- | appender.logfile.strategy.action.ifFileName.ifAny.IfAccumulatedFileCount.type = IfAccumulatedFileCount | + | |
- | appender.logfile.strategy.action.ifFileName.ifAny.IfAccumulatedFileCount.exceeds = 10 | + | |
- | </code> | + | |
===== Reference ===== | ===== Reference ===== | ||
* [[https://logging.apache.org/log4j/2.x/manual/appenders.html|官方Appender設定介紹]] | * [[https://logging.apache.org/log4j/2.x/manual/appenders.html|官方Appender設定介紹]] | ||
* [[https://logging.apache.org/log4j/2.x/manual/layouts.html|官方Layout設定介紹]] | * [[https://logging.apache.org/log4j/2.x/manual/layouts.html|官方Layout設定介紹]] | ||
- | * [[https://www.cnblogs.com/yeyang/p/7944899.html|Log4j2中RollingFile的文件滚动更新机制]] | ||
===== ===== | ===== ===== |