我已将Tomcat配置为使用log4j记录器,如下所述: https://tomcat.apache.org/tomcat-7.0-doc/logging.html
除了webbapp类的日志记录机制外,一切正常。由于某种原因,它没有记录任何东西......
我遇到以下警告:
log4j:WARN No appenders could be found for logger (WEBAPP).
log4j:WARN Please initialize the log4j system properly.
我的log4j.properies(位于$CATALINA_BASE/lib
)看起来像这样:
log4j.rootLogger = INFO,CATALINA,LOCALHOST,CONSOLE,WEBAPP
# Define all the appenders
log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
log4j.appender.CATALINA.File = ${catalina.base}/logs/catalina
log4j.appender.CATALINA.Append = true
log4j.appender.CATALINA.Encoding = UTF-8
log4j.appender.WEBAPP=org.apache.log4j.RollingFileAppender
log4j.appender.WEBAPP.File=${catalina.base}/logs/actions
log4j.appender.WEBAPP.MaxFileSize=4MB
log4j.appender.WEBAPP.MaxBackupIndex=9
log4j.appender.WEBAPP.Append = true
log4j.appender.WEBAPP.Encoding=UTF-8
log4j.appender.WEBAPP.layout=org.apache.log4j.PatternLayout
log4j.appender.WEBAPP.layout.ConversionPattern=%d{dd.MM.yyyy - HH:mm:ss} [[%5p] %c [%t]] %m%n
log4j.category.WEBAPP=INFO
log4j.additivity.WEBAPP=false
# Roll-over the log once per day
log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost
log4j.appender.LOCALHOST.Append = true
log4j.appender.LOCALHOST.Encoding = UTF-8
log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.MANAGER.File = ${catalina.base}/logs/manager
log4j.appender.MANAGER.Append = true
log4j.appender.MANAGER.Encoding = UTF-8
log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager
log4j.appender.HOST-MANAGER.Append = true
log4j.appender.HOST-MANAGER.Encoding = UTF-8
log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Encoding = UTF-8
log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
# Configure which loggers log to which appenders
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\INFO, MANAGER
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\INFO, HOST-MANAGER
我想在一个名为' actions '的特殊日志文件中编写webapp中发生的操作,但是日志文件甚至都没有创建。 webapp在tomcat上运行,除了日志记录之外它工作得很好。 在应该登录到日志文件的webapp类中,有一些初始化的记录器:
private static final Logger LOGGER = LoggerFactory.getLogger("WEBAPP");
我认为这已经足够了但是它还没有工作......
任何建议都会很好,并提前感谢! : - )
答案 0 :(得分:0)
解决了!
我刚刚将WEBAPP添加到log4j.category.WEBAPP=INFO
。与昏迷分开,现在它终于工作了....
所以,这样做
log4j.category.WEBAPP=INFO, WEBAPP
而不是这个
log4j.category.WEBAPP=INFO
它终于有效了。 : - )