当前位置:   article > 正文

Tomcat错误日志控制台不显示_tomcat 启动log控制台看不到

tomcat 启动log控制台看不到

Hello,I'm Shendi


 

目录

 

问题描述

问题解决

1. Create a file called log4j.properties with the following content and save it into $CATALINA_BASE/lib

2.Download Log4J (Tomcat requires v1.2.x).

3.Download or build tomcat-juli.jar and tomcat-juli-adapters.jar that are available as an "extras" component for Tomcat.

4.If you want to configure Tomcat to use log4j globally:

5.If you are running Tomcat with separate $CATALINA_HOME and $CATALINA_BASE and want to configure to use log4j in a single $CATALINA_BASE only:

6.Delete $CATALINA_BASE/conf/logging.properties to prevent java.util.logging generating zero length log files.

7.启动Tomcat


 

问题描述

当我在Eclipse里编写好web程序后,直接在文件系统中启动Tomcat,发现没有错误日志输出了

但是在Eclipse中启动会有日志输出

直接使用命令行的方式跑catalina.bat 也没有作用


问题解决

通过查阅,发现高版本Tomcat默认是不带控制台日志输出的

解决办法就是将默认日志输出替换为 log4j

官网文档,可进入官网自行查看

http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j

 

1. Create a file called log4j.properties with the following content and save it into $CATALINA_BASE/lib

创建log4.properties到Tomcat的lib目录下

默认内容如下

  1. log4j.rootLogger = INFO, CATALINA
  2. # Define all the appenders
  3. log4j.appender.CATALINA = org.apache.log4j.DailyRollingFileAppender
  4. log4j.appender.CATALINA.File = ${catalina.base}/logs/catalina
  5. log4j.appender.CATALINA.Append = true
  6. log4j.appender.CATALINA.Encoding = UTF-8
  7. # Roll-over the log once per day
  8. log4j.appender.CATALINA.DatePattern = '.'yyyy-MM-dd'.log'
  9. log4j.appender.CATALINA.layout = org.apache.log4j.PatternLayout
  10. log4j.appender.CATALINA.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
  11. log4j.appender.LOCALHOST = org.apache.log4j.DailyRollingFileAppender
  12. log4j.appender.LOCALHOST.File = ${catalina.base}/logs/localhost
  13. log4j.appender.LOCALHOST.Append = true
  14. log4j.appender.LOCALHOST.Encoding = UTF-8
  15. log4j.appender.LOCALHOST.DatePattern = '.'yyyy-MM-dd'.log'
  16. log4j.appender.LOCALHOST.layout = org.apache.log4j.PatternLayout
  17. log4j.appender.LOCALHOST.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
  18. log4j.appender.MANAGER = org.apache.log4j.DailyRollingFileAppender
  19. log4j.appender.MANAGER.File = ${catalina.base}/logs/manager
  20. log4j.appender.MANAGER.Append = true
  21. log4j.appender.MANAGER.Encoding = UTF-8
  22. log4j.appender.MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
  23. log4j.appender.MANAGER.layout = org.apache.log4j.PatternLayout
  24. log4j.appender.MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
  25. log4j.appender.HOST-MANAGER = org.apache.log4j.DailyRollingFileAppender
  26. log4j.appender.HOST-MANAGER.File = ${catalina.base}/logs/host-manager
  27. log4j.appender.HOST-MANAGER.Append = true
  28. log4j.appender.HOST-MANAGER.Encoding = UTF-8
  29. log4j.appender.HOST-MANAGER.DatePattern = '.'yyyy-MM-dd'.log'
  30. log4j.appender.HOST-MANAGER.layout = org.apache.log4j.PatternLayout
  31. log4j.appender.HOST-MANAGER.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
  32. log4j.appender.CONSOLE = org.apache.log4j.ConsoleAppender
  33. log4j.appender.CONSOLE.Encoding = UTF-8
  34. log4j.appender.CONSOLE.layout = org.apache.log4j.PatternLayout
  35. log4j.appender.CONSOLE.layout.ConversionPattern = %d [%t] %-5p %c- %m%n
  36. # Configure which loggers log to which appenders
  37. log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost] = INFO, LOCALHOST
  38. log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager] =\
  39. INFO, MANAGER
  40. log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager] =\
  41. INFO, HOST-MANAGER

 

2.Download Log4J (Tomcat requires v1.2.x).

下载log4j,版本最低为1.2

这是官网提供的链接 http://logging.apache.org/log4j

也可以直接通过此链接下载 

http://archive.apache.org/dist/logging/log4j/1.2.17/

 

3.Download or build tomcat-juli.jar and tomcat-juli-adapters.jar that are available as an "extras" component for Tomcat.

下载 tomcat-juli.jar 和 tomcat-juli-adapters.jar

官网链接  http://tomcat.apache.org/tomcat-7.0-doc/extras.html

可以在 http://tomcat.apache.org/download-70.cgi 下找到extras 里找到对应jar

这里直接提供地址了,不确定你是否需要的是这个版本

 

tomcat-juli

https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-7/v7.0.107/bin/extras/tomcat-juli.jar

tomcat-juli-adapters

https://mirrors.bfsu.edu.cn/apache/tomcat/tomcat-7/v7.0.107/bin/extras/tomcat-juli-adapters.jar

4.If you want to configure Tomcat to use log4j globally:

配置Tomcat全局使用log4j

  • Put log4j.jar and tomcat-juli-adapters.jar from "extras" into $CATALINA_HOME/lib.
  • Replace $CATALINA_HOME/bin/tomcat-juli.jar with tomcat-juli.jar from "extras".

将log4j和tomcat-juli-adapters放到Tomcat的lib目录下

将tomcat-juli.jar放入Tomcat的bin目录下,如果有,直接替换

 

5.If you are running Tomcat with separate $CATALINA_HOME and $CATALINA_BASE and want to configure to use log4j in a single $CATALINA_BASE only:

这一部分没啥好说的,一般都不设置自己的目录,所以我就直接用翻译软件复制过来了

如果您使用单独的$ CATALINA_HOME和$ CATALINA_BASE运行Tomcat,并且希望配置为仅在单个$ CATALINA_BASE中使用log4j:

  • 创建$CATALINA_BASE/bin和 $CATALINA_BASE/lib目录(如果不存在)。
  • log4j.jar与 tomcat-juli-adapters.jar从“临时演员”成 $CATALINA_BASE/lib
  • tomcat-juli.jar从“ extras” 放入$CATALINA_BASE/bin/tomcat-juli.jar
  • 如果使用安全管理器运行,则 需要编辑 $CATALINA_BASE/conf/catalina.policy文件以将其调整为使用tomcat-juli.jar的其他副本。

 

6.Delete $CATALINA_BASE/conf/logging.properties to prevent java.util.logging generating zero length log files.

删除conf下的loggin.properties文件

7.启动Tomcat

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/202320?site
推荐阅读
相关标签
  

闽ICP备14008679号