gpt4 book ai didi

java - 让log4j将相同的日志写入多个文件

转载 作者:行者123 更新时间:2023-12-01 22:06:36 31 4
gpt4 key购买 nike

这个配置相当菜鸟;但我在 lo4j.xml 中尝试了下面的配置它不起作用。我想将相同的日志写入两个不同的文件。

 <appender name="FILE" class="com.compname.apt.appender.CustomAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="/home/c/logs/jboss/server.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="BufferedIO" value="false"/>
<param name="BufferSize" value="8096"/>
<!-- Rollover at midnight each day by default -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message -->
<param name="ConversionPattern" value="'[%d] - %x %-5p [%c] %m%n'"/>
</layout>
</appender>
<appender name="flumeappender" class="com.compname.apt.appender.CustomAppender">
<errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
<param name="File" value="/home/y/logs/jboss/flume_ews.log"/>
<param name="Append" value="true"/>
<param name="Threshold" value="INFO"/>
<param name="BufferedIO" value="false"/>
<param name="BufferSize" value="8096"/>
<!-- Rollover at midnight each day by default -->
<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<layout class="org.apache.log4j.PatternLayout">
<!-- The default pattern: Date Priority [Category] Message -->
<param name="ConversionPattern" value="'[%d] - %x %-5p [%c] %m%n'"/>
</layout>
</appender>

最佳答案

这是 log4j 的简单演示。希望这是您需要的东西。

#Destination
log4j.rootLogger=DEBUG, toConsole, toFile, DB

#Console
log4j.appender.toConsole=org.apache.log4j.ConsoleAppender
log4j.appender.toConsole.layout=org.apache.log4j.PatternLayout
log4j.appender.toConsole.layout.ConversionPattern=%d(HH:mm:ss) %5p [%t] - %c.%M - %m%n
#%x: Id, %d: Date, %C: Content,%p: Level, %m: Message
#log4j.appender.toConsole.layout.ConversionPattern=%x %d %C %p %m%n
#https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PatternLayout.html

#DailyRollingFile
log4j.appender.toFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.toFile.File=./log/logfile.txt
log4j.appender.toFile.DatePattern='.' yyyy-MM-dd
log4j.appender.toFile.layout=org.apache.log4j.PatternLayout
log4j.appender.toFile.layout.ConversionPattern=%d(HH:mm:ss) %5p [%t] - %c.%M - %m%n
#log4j.appender.toFile.layout.ConversionPattern=%x %d %C %p %m%n

#JDBCAppender
# Define the file appender
log4j.appender.DB=org.apache.log4j.jdbc.JDBCAppender
log4j.appender.DB.URL=jdbc:sqlserver://localhost:1433;databaseName=Trainees
# Set Database Driver
log4j.appender.DB.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
# Set database user name and password
log4j.appender.DB.user=sa
log4j.appender.DB.password=123456
# Set the SQL statement to be executed.
log4j.appender.DB.sql=INSERT INTO Logs(A,B,C,D) VALUES('%d(HH:mm:ss)', '%5p [%t]', '%c.%M', '%m%n')
# Define the xml layout for file appender
log4j.appender.DB.layout=org.apache.log4j.PatternLayout

关于java - 让log4j将相同的日志写入多个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32656096/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com