【转载】认识Tomcat的日志:catalina.out、localhost、manager、localhost_access_log
一般的web服务器有两部分日志:
一是运行中的日志catalina.out,它主要记录运行的一些信息,尤其是一些异常错误日志信息。
二是访问日志信息access.`date +%F`.log,它记录的访问的时间,IP,访问的资料等相关信息。
日志类别
localhost.Y-M-D.log
经常用到的文件之一 ,程序异常没有被捕获的时候抛出的地方
Tomcat下内部代码丢出的日志
(jsp页面内部错误的异常,org.apache.jasper.runtime.HttpJspBase.service类丢出的,日志信息就在该文件!)
应用初始化(listener, filter, servlet)未处理的异常最后被tomcat捕获而输出的日志,而这些未处理异常最终会导致应用无法启动。
catalina.out
catalina.out其实是tomcat的标准输出(stdout)和标准出错(stderr),
这是在tomcat的启动脚本里指定的,如果没有修改的话stdout和stderr会重定向到这里。
所以我们在应用里使用System.out打印的东西都会到这里来。另外,如果我们在应用里使用其他的日志框架,配置了向Console输出的,则也会在这里出现。
比如以logback为例,如果配置ch.qos.logback.core.ConsoleAppender则会输出到catalina.out里。
catalina.Y-M-D.log
是tomcat自己运行的一些日志,这些日志还会输出到catalina.out,
但是应用向console输出的日志不会输出到catalina.{yyyy-MM-dd}.log
manager.Y-M-D.log
管理的日志
host-manager.Y-M-D.log
虚拟主机方面
localhost_access_log.Y-M-D.txt
tomcat访问日志记录,需要配置
日志的级别
SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value)
日志级别的设置
修改 conf/logging.properties 中的内容,设定某类日志的级别
设置 catalina 日志的级别为: FINE
1catalina.org.apache.juli.FileHandler.level = FINE
禁用 catalina 日志的输出:
1catalina.org.apache.juli.FileHandler.level = OFF
catalina 所有的日志消息均输出:
1catalina.org.apache.juli.FileHandler.level = ALL
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.
- #可配置项(5类日志):catalina、localhost、manager、admin、host-manager
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.
############################################################
#日志输出级别:SEVERE (最高级别) > WARNING > INFO > CONFIG > FINE > FINER(精心) > FINEST (所有内容,最低级别) #配置文件使catalina日志输出级别为FINE1catalina.org.apache.juli.AsyncFileHandler.level = FINE
- #catalina文件输出位置
1catalina.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
- #catalina日志前缀为catalina
1catalina.org.apache.juli.AsyncFileHandler.prefix = catalina.
#配置文件使localhost日志输出级别为FINE
2localhost.org.apache.juli.AsyncFileHandler.level = FINE
- #localhost文件输出位置
2localhost.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
- #localhost日志前缀为localhost
2localhost.org.apache.juli.AsyncFileHandler.prefix = localhost.
#配置文件使manager日志输出级别为FINE
3manager.org.apache.juli.AsyncFileHandler.level = FINE
- #manager文件输出位置
3manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
- #manager日志前缀为manager
3manager.org.apache.juli.AsyncFileHandler.prefix = manager.
#配置文件使host-manager日志输出级别为FINE
4host-manager.org.apache.juli.AsyncFileHandler.level = FINE
- #host-manager文件输出位置
4host-manager.org.apache.juli.AsyncFileHandler.directory = ${catalina.base}/logs
- #host-manager日志前缀为host-manager
4host-manager.org.apache.juli.AsyncFileHandler.prefix = host-manager.
#配置文件使控制台日志输出级别为FINE
java.util.logging.ConsoleHandler.level = FINE
- #控制台日志输出格式
java.util.logging.ConsoleHandler.formatter = org.apache.juli.OneLineFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
#localhost日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].level = INFO
- #localhost日志文件输出处理类2localhost.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.AsyncFileHandler
#manager日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].level = INFO
- #manager日志文件输出处理类3manager.org.apache.juli.FileHandler
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/manager].handlers = 3manager.org.apache.juli.AsyncFileHandler
#host-manager日志文件输出级别为INFO
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].level = INFO
- #host-manager日志文件输出处理类4host-manager.org.apache.juli.FileHandler
- org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/host-manager].handlers = 4host-manager.org.apache.juli.AsyncFileHandler
# For example, set the org.apache.catalina.util.LifecycleBase logger to log
# each component that extends LifecycleBase changing state:
#org.apache.catalina.util.LifecycleBase.level = FINE
# To see debug messages in TldLocationsCache, uncomment the following line:
#org.apache.jasper.compiler.TldLocationsCache.level = FINE