gpt4 book ai didi

tomcat - 如何防止 spring boot 同时登录到指定文件和 catalina.out

转载 作者:行者123 更新时间:2023-11-28 22:26:22 27 4
gpt4 key购买 nike

我在一个 spring-boot 项目(版本 1.5.1)中工作并使用 logback。我的 application.properties 具有以下日志设置:

logging.level.=info
logging.level.org.acme.myapp=info
logging.file=${catalina.home}/logs/AppLogFile.log

当应用程序记录某些内容时,会将其写入指定的 AppLogFile.log 以及 catalina.out:

==> AppLogFile.log <==
2017-04-13 13:37:33.102 DEBUG 4646 --- [http-nio-8080-exec-25] c.l.c.c.controller.IndexPage : isAllowedToSeeContent: Homebase: MOCKBASE

==> catalina.out <==
2017-04-13 13:37:33.102 DEBUG 4646 --- [io-8080-exec-25] c.l.c.c.controller.IndexPage : isAllowedToSeeContent: Homebase: MOCKBASE

==> AppLogFile.log <==
2017-04-13 13:37:33.108 DEBUG 4646 --- [http-nio-8080-exec-25] c.l.c.c.controller.MedlistService : MedlistService::isControlDay 2017-04-13, true

==> catalina.out <==
2017-04-13 13:37:33.108 DEBUG 4646 --- [io-8080-exec-25] c.l.c.c.controller.MedlistService : MedlistService::isControlDay 2017-04-13, true

这好像是可加性的问题。是否真的有必要像此处提到的那样提供 logback.xml:howto-configure-logback-for-logging ?还是有更直接的方法?


更新:

即使我遵循 howto 的建议并将 logback-spring.xml 添加到我的类路径中:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}" />
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root>
<appender-ref ref="FILE" />
</root>
</configuration>

我收到以下错误(大量):

17:50:01.267 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [LOGGING_patternLevel] threw NamingException with message: Name [LOGGING_patternLevel] is not bound in this Context. Unable to find [LOGGING_patternLevel].. Returning null.
17:50:01.267 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/LOGGING_patternlevel]

logging.pattern.console= 设置为一个空字符串,似乎可以解决问题 - 但这真的是正确的解决方案吗?

最佳答案

您的 tomcat 的 conf/logging.properties 是否包含以下行?

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

这是默认包的一部分。从中删除 ConsoleHandler 条目。

关于tomcat - 如何防止 spring boot 同时登录到指定文件和 catalina.out,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43391599/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com