1. 程式人生 > >tomcat默認日誌路徑更改

tomcat默認日誌路徑更改

specific war 一個 asf arr 目錄 writing file direct

在項目訪問量不斷增加時,tomcat下logs也迅速增大,有時甚至因為填滿了所在分區而出現無空間寫入日誌而導致程序出問題。

這時要更改logs的默認目錄,指向更大的磁盤。修改主要有兩步:

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.AsyncFileHandler, 2localhost.org.apache.juli.AsyncFileHandler, 3manager.org.apache.juli.AsyncFileHandler, 4host-manager.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler .handlers
= 1catalina.org.apache.juli.AsyncFileHandler, java.util.logging.ConsoleHandler ############################################################ # Handler specific properties. # Describes specific configuration info for Handlers. ############################################################ 1catalina.org.apache.juli.AsyncFileHandler.level = FINE 1catalina.org.apache.juli.AsyncFileHandler.directory = /data/logs/tomcat8log/logs 1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina. 2localhost.org.apache.juli.AsyncFileHandler.level = FINE 2localhost.org.apache.juli.AsyncFileHandler.directory = /data/logs/tomcat8log/logs 2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost. 3manager.org.apache.juli.AsyncFileHandler.level = FINE 3manager.org.apache.juli.AsyncFileHandler.directory = /data/logs/tomcat8log/logs 3manager.org.apache.juli.AsyncFileHandler.prefix = manager. 4host-manager.org.apache.juli.AsyncFileHandler.level = FINE 4host-manager.org.apache.juli.AsyncFileHandler.directory = /data/logs/tomcat8log/logs 4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager. java.util.logging.ConsoleHandler.level = FINE java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter


把其中各個directory路徑更改為要存儲對應日誌的路徑,一般都是設置為同一個地方。

2. 修改tomcat/bin/catalina.sh

if [ -z "$CATALINA_OUT" ] ; then
  CATALINA_OUT=/data/logs/tomcat8log/logs/catalina.out
fi

把CATALINA_OUT修改為與logging.properties修改一樣的路徑,便於日誌集中管理。

重啟tomcat就能看到diska/tomcatlog/logs/下開始產生新日誌了。

tomcat默認日誌路徑更改