其他项目上使用log4j 能把日志输入到指定的文件中
同样的操作放在ssh2项目里面出现如下提示:log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources).
log4j:WARN Please initialize the log4j system properly.
百度只能输入log4j:WARN No appenders could be found for logger 这些字段所以这个问题百度没有找到...
类似的这样的问题都说没有加log4j.properties文件,可是我加了,而且在其他项目里面都正常什么原因哦

解决方案 »

  1.   

    默认放到src目录下,如果不是,需要在web.xml里面配置下
      

  2.   

    把下面的放在log4j.properties里试下
    # This is the configuring for logging displayed in the Application Server
    log4j.rootCategory=INFO, stdout# Replace the line above if you want to put a log file into the directory 
    # you start Tomcat from
    # log4j.rootCategory=INFO, stdout, Rlog4j.appender.stdout=org.apache.log4j.RollingFileAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout# Pattern to output the caller's file name and line number.
    #log4j.appender.stdout.layout.ConversionPattern=[@APPNAME@] %p [%t] %c{1}.%M(%L) | %m%n
    log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p]  %m%n
    log4j.appender.stdout.MaxFileSize=3mb
    log4j.appender.stdout.MaxBackupIndex=1
    log4j.appender.stdout.file=d:\\output.log 
    log4j.appender.R=org.apache.log4j.RollingFileAppender# You can change this to be an absolute path or even an environment variable
    # If you're using an environment variable, you will have to set JAVA_OPTS
    # to contain this variables - for example in the catalina.sh or catalina.bat
    # filelog4j.appender.R.File=@[email protected]=100KB# Don't keep a backup file
    log4j.appender.R.MaxBackupIndex=0log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n# Configuration for receiving e-mails when ERROR messages occur.
    log4j.appender.mail=org.apache.log4j.net.SMTPAppender
    log4j.appender.mail.To=@ERROR-MAILTO@
    log4j.appender.mail.From=@ERROR-SERVER@@raibledesigns.com
    log4j.appender.mail.SMTPHost=@ERROR-MAILHOST@
    log4j.appender.mail.Threshold=ERROR
    log4j.appender.mail.BufferSize=1
    log4j.appender.mail.Subject=[@ERROR-SERVER@] @APPNAME@ Application Errorlog4j.appender.mail.layout=org.apache.log4j.PatternLayout
    log4j.appender.mail.layout.ConversionPattern=%d  %-5p %c %x - %m%n# If programmed properly the most messages would be at DEBUG 
    # and the least at FATAL.
    log4j.logger.com.relationinfo=DEBUG
    log4j.logger.com.relationinfo.webapp.filter=ERROR
    log4j.logger.com.relationinfo.webapp.listener.UserCounterListener=WARN
    log4j.logger.com.relationinfo.util=WARN# Control logging for other open source packages
    log4j.logger.com.opensymphony.oscache=ERROR
    log4j.logger.net.sf.navigator=ERROR
    log4j.logger.net.sf.acegisecurity=WARN
    log4j.logger.net.sf.acegisecurity.intercept.event.LoggerListener=WARN
    log4j.logger.org.apache.commons=ERROR
    log4j.logger.org.apache.struts=WARN
    log4j.logger.org.displaytag=ERROR
    log4j.logger.org.springframework=WARN
    log4j.logger.com.ibatis.db=WARN
    log4j.logger.org.apache.velocity=WARN
    log4j.logger.org.codehaus.xfire=WARN
    # Don't show debug logs for WebTest
    log4j.logger.com.canoo.webtest=WARN# All hibernate log output of "info" level or higher goes to stdout.
    # For more verbose logging, change the "info" to "debug" on the last line.
    log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN
    log4j.logger.org.hibernate=WARN# Changing the log level to DEBUG will result in Hibernate generated
    # SQL to be logged.
    log4j.logger.org.hibernate.SQL=ERROR# Changing the log level to DEBUG will result in the PreparedStatement
    # bound variable values to be logged.
    log4j.logger.org.hibernate.type=ERROR