在開發/測試環境,日志是非常重要的。而公司對于測試環境進行了控制,只有配置人員能連接訪問,而開發人員是無法獲取該服務器的信息的。在出現錯誤時,沒有異常日志,開發是很難重現問題的。因此需要對中間件 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
?
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
