java Spring Boot 中的日志文件端点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33938997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:19:05  来源:igfitidea点击:

logfile endpoint in Spring Boot

javaspringspring-boot

提问by ps-aux

I read Spring Boot Actuator documentationand saw logfileendpoint mentioned there which would really come in handy.

我阅读了 Spring Boot Actuator文档并看到了logfile那里提到的端点,这真的会派上用场。

However this endpoint is not registered in my app and I have no idea how to make it available. What is needed here?

但是,此端点未在我的应用程序中注册,我不知道如何使其可用。这里需要什么?

回答by Gergely Bacso

In order to enable this feature, one of these two params need to be set:

为了启用此功能,需要设置以下两个参数之一:

  • logging.file
  • logging.path
  • logging.file
  • logging.path

Logging configuration

日志配置

After that the endpoint should be enabled by default.

之后,端点应默认启用。

回答by Jan69

I added below code to enable /logfile endpoint

我添加了以下代码以启用 /logfile 端点

pom.xml
-----------

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>


application.properties
-----------------------

management.security.enabled=false
endpoints.env.enabled=false
endpoints.configprops.enabled=false
endpoints.autoconfig.enabled=false
endpoints.beans.enabled=false
endpoints.dump.enabled=true
endpoints.heapdump.enabled=true
logging.level.root=info
logging.file=target/app.log

回答by Allahbaksh Asadullah

I had below lines in my application.properties . I am using spring-boot with actuator

我的 application.properties 中有以下几行。我正在使用带有执行器的弹簧靴

logging.file.name=./logs/log-file.log
management.endpoints.web.exposure.include=*

Without the management extension line, the response was

Without the management extension line, the response was

Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Dec 04 05:04:40 IST 2019 There was an unexpected error (type=Not Found, status=404). No message available

回答by user3283865

I had used below for

I had used below for

version 2.1.3 -> management.endpoint.logfile=C:/apps/Benefits-logs/adapt-rest.log as you can see class LogFileWebEndpointProperties

version 2.1.3 -> management.endpoint.logfile=C:/apps/Benefits-logs/adapt-rest.log as you can see class LogFileWebEndpointProperties

and this also works logging.file=C:/apps/Benefits-logs/adapt-rest.log

and this also works logging.file=C:/apps/Benefits-logs/adapt-rest.log

No need to add logging.path. If you see LogFileCondition class you will get to know.

No need to add logging.path. If you see LogFileCondition class you will get to know.