【问题标题】:Tomcat is not logging to fileTomcat没有记录到文件
【发布时间】:2012-03-16 19:17:18
【问题描述】:

我正在尝试使用 doc - http://tomcat.apache.org/tomcat-7.0-doc/logging.html 登录到文件

这是我在 tomcat_home/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}/logs
1catalina.org.apache.juli.FileHandler.prefix = catalina.

2localhost.org.apache.juli.FileHandler.level = FINE
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.prefix = localhost.

3manager.org.apache.juli.FileHandler.level = FINE
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/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}/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 = DEBUG
org.apache.catalina.core.ContainerBase.[Catalina].[localhost].handlers = 2localhost.org.apache.juli.FileHandler

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

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

# 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

这里是 /src/main/webapp/WEB-INF/classes 的 logging.properties

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

############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################

org.apache.juli.FileHandler.level = FINE
org.apache.juli.FileHandler.directory = ${catalina.base}/logs
org.apache.juli.FileHandler.prefix = mywebapp

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

但是日志文件没有被创建,我错过了什么吗?

【问题讨论】:

    标签: tomcat tomcat7


    【解决方案1】:

    对我来说,这个问题是由以下原因引起的:catalina.base 设置不正确,因此 tomcat 试图写入一个不存在的目录。

    更新:catalina.base 设置的目录不存在

    【讨论】:

    • 你是怎么知道这个问题的?如何检查我是否也出于同样的原因面临这个问题?
    • @Dwhitz 我更新了答案,不知道如何让这个答案更清晰。
    • 谢谢,这么简单..是我的错,我在考虑一些覆盖配置。
    • 那你是怎么设置的?
    【解决方案2】:

    遇到同样的问题。在我的情况下,问题是由于运行 tomcat 服务的用户缺乏对日志目录的写访问权限引起的。

    【讨论】:

    • 如何查看运行tomcat服务的用户以及该用户是否有访问权限?
    • 先用本地系统账号运行服务,如果运行则说明没有写权限。
    【解决方案3】:

    尝试手动初始化目录,例如 E:/_logs/tomcat7,您希望在其中放置日志文件而不是 ${catalina.base}/logs

    【讨论】:

    • 如果不是windows你会怎么做呢?如果您在 Windows 机器上,这只能在 @local 上使用。根本不推荐用于任何其他环境。
    猜你喜欢
    • 2016-09-29
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    相关资源
    最近更新 更多