简体   繁体   English

添加日志记录后,为什么 Spring Boot 应用程序无法完全启动?

[英]Why spring boot application does not start fully after adding logging?

Collegues, this is part of my pom:同事们,这是我的 pom 的一部分:

<dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter</artifactId>
                    <version>1.2.5.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j</artifactId>
            <version>1.2.5.RELEASE</version>
        </dependency>

this is my \\src\\main\\resources\\log4j.xml这是我的 \\src\\main\\resources\\log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <!-- Appenders -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Target" value="System.out" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p: [%d{MMM-dd HH:mm:ss,SSS}] %c{3} - %m%n" />
        </layout>
    </appender>


    <!-- File Appender -->
    <appender name="file" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="C:/LOGS/spring-ws.log"/>
        <param name="MaxFileSize" value="10000KB"/>
        <param name="MaxBackupIndex" value="20"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%-5p: [%d{MMM-dd HH:mm:ss,SSS}] %c{3} - %m%n" />
        </layout>
    </appender>

   <logger name="org.springframework.ws.server.MessageTracing.received">
    <level value="TRACE"/>
    <appender-ref ref="console"/> 
    <appender-ref ref="file"/>
   </logger> 


   <logger name="org.springframework.ws.server.MessageTracing.sent">
    <level value="TRACE"/> 
    <appender-ref ref="console"/>
    <appender-ref ref="file"/>
   </logger>

</log4j:configuration>

After

mvn package spring-boot:repackage mvn 包 spring-boot:repackage

and

java -jar target/app-ws.jar java -jar 目标/app-ws.jar

I receive only我只收到

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.2.5.RELEASE)

and nothing more.仅此而已。

Also application create C:/LOGS/spring-ws.log, but it is empty.也应用程序创建 C:/LOGS/spring-ws.log,但它是空的。

Why spring boot application does not start?为什么spring boot应用程序不启动?

The problem was solved by adding into log4j.xml next looger: 通过在log4j.xml中添加下一个looger来解决问题:

 <logger name="org.springframework.boot">
        <level value="trace"/>
        <appender-ref ref="console"/>
        <appender-ref ref="file"/>
 </logger>

Hope this will help to somebody. 希望这会对某人有所帮助。

You can add a property in application.properties as: 您可以在application.properties中添加属性:

logging.level.root=INFO

This will show sufficient amount of info to let you know about mappings and basic application info. 这将显示足够的信息,让您了解映射和基本应用程序信息。 Other logging levels that you may use are(source: logging ): 您可以使用的其他日志记录级别是(源: 日志记录 ):

Level Description 等级描述

  • FATAL : Severe errors that cause premature termination. 致命:导致提前终止的严重错误。 Expect these to be immediately visible on a status console. 期望这些在状态控制台上立即可见。
  • ERROR : Other runtime errors or unexpected conditions. 错误:其他运行时错误或意外情况。 Expect these to be immediately visible on a status console. 期望这些在状态控制台上立即可见。
  • WARNING 警告
  • INFO Interesting runtime events (startup/shutdown). INFO有趣的运行时事件(启动/关闭)。 Expect these to be immediately visible on a console, so be conservative and keep to a minimum. 期望这些在控制台上立即可见,所以保守并保持最低限度。
  • DEBUG detailed information on the flow through the system. DEBUG有关通过系统的流量的详细信息。 Expect these to be written to logs only. 期望这些只写入日志。
  • TRACE more detailed information. 跟踪更详细的信息。 Expect these to be written to logs only. 期望这些只写入日志。

Probabilly you missed this可能你错过了这个

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 maven 依赖项中添加 pubnub 后,Spring Boot 应用程序不启动 - Spring boot application does not start after adding pubnub in maven dependency 添加 ssl 证书 spring 启动应用程序无法启动后 - After adding ssl certificate spring boot application fails to start Spring启动应用程序无法启动 - Spring boot application does not start 升级到 Spring Boot 2 后应用程序无法启动 - Application fails to start after upgrading to Spring Boot 2 为什么Spring Boot中的H2控制台登录后显示黑屏? - Why does the H2 console in Spring Boot show a blank screen after logging in? 为什么 Log4j2 没有在 Spring 引导应用程序中登录? - Why is Log4j2 not logging inside Spring Boot Application? 用于记录的Spring Boot应用程序属性 - spring boot application properties for logging 应用程序不是从Spring Boot 1.2.1 + Spring Security + Servlet 2.5开始的 - Application does not start with Spring Boot 1.2.1 + Spring Security + Servlet 2.5 添加 junit 测试时,Spring 启动应用程序无法启动 - Spring boot application fails to start when adding junit tests Spring Boot JPA应用程序无法从Spring Boot 2.0.2启动,并且可以在Spring Boot 1.5.13上正常运行 - Spring Boot JPA application does not start with spring boot 2.0.2 and it works fine with Spring boot 1.5.13
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM