更改 Tomcat 日志路径

系统 1615 0

在开发/测试环境,日志是非常重要的。而公司对于测试环境进行了控制,只有配置人员能连接访问,而开发人员是无法获取该服务器的信息的。在出现错误时,没有异常日志,开发是很难重现问题的。因此需要对中间件 tomcat 进行配置,将日志放到某个目录下,开发人员可以通过浏览器就能查看日志。ok,开工:

目的 : 能通过浏览器检查tomcat日志

方法 :将 tomcat 的日志放置到 $CATALINA_HOME/webapps/ROOT/logs 下,用户就可以通过 http://xxx.xxx.xxx.xxx/logs/catalina.out 访问日志了。

1. 修改tomcat/conf下的logging.properties 

      
        # Licensed to the Apache Software Foundation (ASF) under one or more

# contributor license agreements.  See the NOTICE file distributed with

# this work for additional information regarding copyright ownership.

# The ASF licenses this file to You under the Apache License
      
      , Version 2.0
      
        

# (the 
      
      "License")
      
        ;
      
      
         you may not use this file except in compliance with
      
      
        # the License.  You may obtain a copy of the License at

#

#     http://www.apache.org/licenses/LICENSE-
      
      2.0
      
        

#

# Unless required by applicable law or agreed to in writing
      
      ,
      
         software

# distributed under the License is distributed on an 
      
      "AS IS" BASIS,
      
        

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND
      
      ,
      
         either express or implied.

# See the License for the specific language governing permissions and

# limitations under the License.



handlers 
      
      = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler,
      
         java.util.logging.ConsoleHandler



.handlers 
      
      = 1catalina.org.apache.juli.FileHandler,
      
         java.util.logging.ConsoleHandler



############################################################

# Handler specific properties.

# Describes specific configuration info for Handlers.

############################################################



1catalina.org.apache.juli.FileHandler.level 
      
      =
      
         FINE

1catalina.org.apache.juli.FileHandler.directory 
      
      =
      
        
          
             ${catalina.base}/webapps/ROOT/logs
          
        
        

1catalina.org.apache.juli.FileHandler.prefix 
      
      =
      
         catalina.



2localhost.org.apache.juli.FileHandler.level 
      
      =
      
         FINE

2localhost.org.apache.juli.FileHandler.directory 
      
      =
      
        
          
             ${catalina.base}/webapps/ROOT/logs
          
        
        

2localhost.org.apache.juli.FileHandler.prefix 
      
      =
      
         localhost.



3manager.org.apache.juli.FileHandler.level 
      
      =
      
         FINE

3manager.org.apache.juli.FileHandler.directory 
      
      =
      
        
          
             ${catalina.base}/webapps/ROOT/logs
          
        
        

3manager.org.apache.juli.FileHandler.prefix 
      
      =
      
         manager.



4host-manager.org.apache.juli.FileHandler.level 
      
      =
      
         FINE

4host-manager.org.apache.juli.FileHandler.directory 
      
      =
      
        
          
             ${catalina.base}/webapps/ROOT/logs
          
        
        

4host-manager.org.apache.juli.FileHandler.prefix 
      
      =
      
         host-manager.



java.util.logging.ConsoleHandler.level 
      
      =
      
         FINE

java.util.logging.ConsoleHandler.formatter 
      
      =
      
         java.util.logging.SimpleFormatter





############################################################

# Facility specific properties.

# Provides extra control for each logger.

############################################################



org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .level =
      
         INFO

org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .handlers =
      
         2localhost.org.apache.juli.FileHandler



org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .
      
        [
      
      
        /manager
      
      
        ]
      
      .level =
      
         INFO

org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .
      
        [
      
      
        /manager
      
      
        ]
      
      .handlers =
      
         3manager.org.apache.juli.FileHandler



org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .
      
        [
      
      
        /host-manager
      
      
        ]
      
      .level =
      
         INFO

org.apache.catalina.core.ContainerBase.
      
      
        [
      
      
        Catalina
      
      
        ]
      
      .
      
        [
      
      
        localhost
      
      
        ]
      
      .
      
        [
      
      
        /host-manager
      
      
        ]
      
      .handlers =
      
         4host-manager.org.apache.juli.FileHandler



# For example
      
      ,
      
         to log debug messages in ContextConfig and HostConfig

# classes and to log only warnings and errors in other

# org.apache.catalina.** classes
      
      ,
      
         uncomment these lines:

#org.apache.catalina.startup.ContextConfig.level 
      
      =
      
         FINE

#org.apache.catalina.startup.HostConfig.level 
      
      =
      
         FINE

#org.apache.catalina.level 
      
      = WARNING
    

 

2. 修改tomcat/bin/catalina.sh 

 

      186 if [ -z "$CATALINA_OUT" ] ; then

187   CATALINA_OUT=
      
        
          "$CATALINA_BASE"/webapps/ROOT/logs/catalina.out
        
      
      

188 fi


    

【注意】红色字体是需要修改的内容,修改为当前 tomcat 的最新的网站根目录即可。

 

3、重启 tomcat

4、使用浏览器即可查看日志: http://xxx.xxx.xxx.xxxx/logs/catalina.out

 

更改 Tomcat 日志路径


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论