日志文件未填充日志信息

时间:2013-06-15 12:37:50

标签: java log4j

我有log4j.properties以下,并且未创建指定的日志文件。我使用的是log4j-1.2.13版本。     能帮到我。

**log4j.properties:**

log4j.logger.kmc.debug=INFO,console,file

log4j.appender.AuditFile=org.apache.log4j.RollingFileAppender
log4j.appender.AuditFile.File=${log.dir}/rkm_java_client_audit.log
log4j.appender.AuditFile.MaxFileSize=100KB
log4j.appender.AuditFile.MaxBackupIndex=2
log4j.appender.AuditFile.layout=org.apache.log4j.PatternLayout
log4j.appender.AuditFile.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm:ssZ}


# Audit logs to EventLog on a Windows system.
log4j.appender.AuditEventlog=org.apache.log4j.nt.NTEventLogAppender
log4j.appender.AuditEventlog.Source=RKMJavaClient_2_1
#log4j.appender.AuditEventlog.Threshold=INFO
log4j.appender.AuditEventlog.layout=org.apache.log4j.PatternLayout
log4j.appender.AuditEventlog.layout.ConversionPattern=%m%n

log4j.appender.console=org.apache.log4j.ConsoleAppender

2 个答案:

答案 0 :(得分:0)

您需要在log4j.properties中配置文件appender。以下是如何做到这一点:

log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\loging.log 
log4j.appender.file.MaxFileSize=1MB log4j.appender.file.MaxBackupIndex=1 
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n**

请点击此链接了解详情:http://www.mkyong.com/logging/log4j-log4j-properties-examples/

答案 1 :(得分:0)

您可能需要添加以下行(通常在开头):

# Set root logger level to INFO and its appenders to console, file.
log4j.rootLogger=INFO, console, file

见下一个例子:

# Set root logger level to INFO and appender to ROLL.
log4j.rootLogger=INFO, ROLL

#-----------------------------------STDOUT-----------------------------------#
# STDOUT is set to be a ConsoleAppender.
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
# STDOUT uses PatternLayout.
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%d %-5p (%c.java:%L).%M - %m%n

#------------------------------------ROLL------------------------------------#
# ROLL is set to be a RollingFileAppender.
log4j.appender.ROLL=org.apache.log4j.RollingFileAppender

log4j.appender.ROLL.File=/logs/myFile.log
log4j.appender.ROLL.MaxFileSize=1MB
# Keep five backup files
log4j.appender.ROLL.MaxBackupIndex=5

log4j.appender.ROLL.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLL.layout.ConversionPattern=%d %-5p %c.%M:%L - %m%n

log4j.appender.ROLL.Encoding=UTF-8

#----------------------------------------------------------------------------#
# Specify the logging level for loggers from other libraries

log4j.logger.org.apache.struts.util.PropertyMessageResources=ERROR
log4j.logger.com.ibm._jsp=DEBUG

#----------------------------------------------------------------------------#
# http://logging.apache.org/log4j/1.2/manual.html