我正在开发基于桌面的应用程序,但无法在客户端桌面上生成log4j文件。
我的log4j.property文件是:
log4j.rootLogger=DEBUG, SECOND_APPENDER
log4j.appender.NotConsole=org.apache.log4j.RollingFileAppender
log4j.appender.NotConsole.maxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%m%n
log4j.appender.file.File=C:\\log4j-application.log
log4j.logger.com.jd.listing=DEBUG,SECOND_APPENDER
我的log4j.xml文件是:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="log4j.test"
status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="log4j.test.Log4jTest" level="trace">
<AppenderRef ref="Console"/>
</Logger>
<Root level="trace">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
请帮我在我的驱动器上生成log4j文件。 提前致谢
答案 0 :(得分:0)
试试这个,我用stdout替换了SECOND_APPENDER并添加了stdout
log4j.rootLogger=DEBUG, stdout, R
log4j.appender.NotConsole=org.apache.log4j.RollingFileAppender
log4j.appender.NotConsole.maxFileSize=20MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%m%n
log4j.appender.file.File=C:\\log4j-application.log
log4j.logger.com.jd.listing=DEBUG
# Standard output logging
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd-HH-mm-ss}[%x]::[%t]:(%l:%L):%-5p:%c{1}:%m%n
# Rolling file logging
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=mylogfile.log
log4j.appender.R.MaxFileSize=5MB
log4j.appender.R.MaxBackupIndex=3
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{MMM:dd:HH:mm:ss,SSS}:[%t]:(%C{1}.%M:%L):%-5p:%c{1}:%m%n
不需要log4j.xml。