[Record] SpringBoot 2.X integration Log4j no output INFO, DEBUG and other log information solutions

As the batch update time has been unable to locate the source of the problem, go to the positioning server logs, but since has been unable to log output, in order to better locate the problem, learn from their mistakes and gradually after the final investigation to solve the problem. If Keguan see here, please do not blindly condemnation, my project environment may have differences with you so the solution is not necessarily suitable, Citie only as a work record, and the same problem and the same project environment as a friend learn from it, if there is no help, please mouth mercy.

First posted log file: log4j2.yml

# Eight levels, from low to high in accordance with: ALL <the TRACE <the DEBUG <the INFO <WARN <ERROR <FATAL < OFF. 
The Configuration: 
  Status: info 
  MonitorInterval: 30 
  the Properties: # define global variables 
    Property: # default configuration (for development environments). Other VM environments need to specify parameters, as follows:
       - = Dlog.level.console info
       - name: log.level.console 
        value: Debug
       - name: log.path 
        value: /data/txv1.0/tx-data/ logs
       - name: the project.name 
        value: TX_Data
       - name: log.pattern 
        value: "% D {the mM-dd-YYYY HH: mm: ss.SSS} - {% $ the PID 5P: -} [15.15t%]% - {. 1 30.30C.}:%% n-m " 
  Appenders: 
    console: # output to the console
      name: the CONSOLE 
      target: SYSTEM_OUT 
      the PatternLayout: 
        pattern: log.pattern} $ { 
# start log 
    RollingFile:
       - name: ROLLING_FILE 
        fileName: log.path} {$ / $ {} .log the project.name 
        filePattern: "$ {log.path } / historyRunLog / $$ {DATE: the MM-YYYY} / {the project.name} $ -% D-the MM-YYYY {dd} -% i.log.gz " 
        the PatternLayout: 
          pattern: $ {} log.pattern 
        the Filters: 
# must first remove the log level is not acceptable, then get the need to accept the log level 
          ThresholdFilter:
             - level: fatal 
              onMatch: DENY 
              onMismatch: NEUTRAL
             - level: Debug
              onMatch: ACCEPT
              onMismatch: DENY
        Policies:
          TimeBasedTriggeringPolicy:  # 按天分类
            modulate: true
            interval: 1
        DefaultRolloverStrategy:     # 文件最多100个
          max: 100
#   平台日志
      - name: PLATFORM_ROLLING_FILE
        ignoreExceptions: false
        fileName: ${log.path}/platform/${project.name}_platform.log
        filePattern: "${log.path}/platform/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz"
        PatternLayout:
          pattern: $ {} log.pattern 
        Policies:
          TimeBasedTriggeringPolicy: # classified by day 
            modulate &: to true 
            interval The: . 1 
        DefaultRolloverStrategy: # File up to 100 
          max: 100 
# traffic log
       - name: BUSSINESS_ROLLING_FILE 
        ignoreExceptions: to false 
        fileName: $ {} log.path / bussiness / $ {} _bussiness.log the project.name 
        filePattern: "$ {} log.path / bussiness / $$ {DATE: the MM-YYYY} / {the project.name} $ -% D-the MM-YYYY {dd} -% i.log.gz " 
        the PatternLayout: 
          pattern: $ {} log.pattern 
        Policies: 
          TimeBasedTriggeringPolicy: # classified by day
            modulate: true
            interval: 1
        DefaultRolloverStrategy:     # 文件最多100个
          max: 100
#   错误日志
      - name: EXCEPTION_ROLLING_FILE
        ignoreExceptions: false
        fileName: ${log.path}/exception/${project.name}_exception.log
        filePattern: "${log.path}/exception/$${date:yyyy-MM}/${project.name}-%d{yyyy-MM-dd}-%i.log.gz"
        ThresholdFilter:
          level: error
          onMatch: ACCEPT
          onMismatch: DENY
        PatternLayout:
          pattern: ${log.pattern}
        Policies:
          TimeBasedTriggeringPolicy: # classified by day 
            modulate &: to true
            interval The: . 1 
        DefaultRolloverStrategy: # File up to 100 
          max: 100 
# log DB
       - name: DB_ROLLING_FILE 
        ignoreExceptions: to false 
        fileName: $ {} log.path / DB / $ {} _db.log the project.name 
        filePattern: "$ {log. } path / DB / $$ {DATE: the MM-YYYY} / {the project.name} $ -% D-the MM-YYYY {dd} -% i.log.gz " 
        the PatternLayout: 
          pattern: $ {} log.pattern 
        Policies : 
          TimeBasedTriggeringPolicy: # classification by day 
            modulate: to true 
            interval The: 1 
        DefaultRolloverStrategy: # Up to 100 files
          max: 100
  Loggers:
    Root:
      level: debug
      AppenderRef:
        - ref: CONSOLE
        - ref: ROLLING_FILE
        - ref: PLATFORM_ROLLING_FILE
        - ref: BUSSINESS_ROLLING_FILE
        - ref: EXCEPTION_ROLLING_FILE
        - ref: DB_ROLLING_FILE
    Logger:
      - name: rolling
        level: info
        additivity: true
        AppenderRef:
          - ref: CONSOLE
          - ref: ROLLING_FILE
      - name: platform
        level: debug
        additivity: true
        AppenderRef:
          - ref: CONSOLE
          - ref: PLATFORM_ROLLING_FILE
      - name: bussiness
        level: info
        additivity: true
        AppenderRef:
          - ref: CONSOLE
          - ref: BUSSINESS_ROLLING_FILE
      - name: exception
        level: debug
        additivity: true
        AppenderRef:
          - ref: CONSOLE
          - ref: EXCEPTION_ROLLING_FILE
      - name: db
        level: debug
        additivity: true
        AppenderRef:
          - ref: CONSOLE
          - ref: DB_ROLLING_FILE

Disclaimer: This file format is an online reference and forget what is called the friend of any similarity please understand that I may learn from you.

Posted rely pom original document (part, associated with the log)

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <!-- 排除自带的日志依赖 -->
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- 配置 log4j2 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
        </dependency>
    
        ..........

        <!-- 云服务依赖包 start -->
        <dependency>
            <groupId>com.qiniu</groupId>
            <artifactId>qiniu-java-sdk</artifactId>
            <version>${qiniu-version}</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun.oss</groupId>
            <artifactId>aliyun-sdk-oss</artifactId>
            <version>${aliyun-oss-version}</version>
        </dependency>
        <dependency>
            <groupId>com.qcloud</groupId>
            <artifactId>cos_api</artifactId>
            <version>${qcloud-cos-version}</version>
        </dependency>
        <!-- 云服务依赖包 end -->
</dependencies>

Since the re-start after a server there has been such a warning

SLF4J: Class path SLF4J the contains Multiple Bindings. 
SLF4J: Found in the Binding [JAR: File: /data/txv1.0/tx-data/webapps/tx-data/WEB-INF/lib/slf4j-log4j12-1.7.25. ! JAR / ORG / SLF4J / impl / StaticLoggerBinder. class ] 
SLF4J: Found in the Binding [JAR: File: /data/txv1.0/tx-data/webapps/tx-data/WEB-INF/lib/log4j-slf4j- ! impl-2.11.2.jar / ORG / SLF4J / impl / StaticLoggerBinder. class ] 
SLF4J: See HTTP: // www.slf4j.org/codes.html#multiple_bindings for AN explanation. 
SLF4J: Actual IS of the Binding of the type [ORG .slf4j.impl.Log4jLoggerFactory] 

after much investigation found that the warning is prompted to rely on conflict of slf4j-log4j12-xxx.jar

And whether there are related by pom file logger investigation slf4j-log4j12-xxx.jar packet collisions as

The figure is dependent on the conflict so I removed the invisible dependent packages, if there appears to be dependent rely on those jar, eventually found to be dependent jar package

<dependency>
    <groupId>com.qiniu</groupId>
    <artifactId>qiniu-java-sdk</artifactId>
    <version>${qiniu-version}</version>
</dependency>

Finally, the package is removed depends slf4j-log4j12-xxx.jar package, to solve problems such as log information output method.

<dependency>
    <groupId>com.qcloud</groupId>
    <artifactId>cos_api</artifactId>
    <version>${qcloud-cos-version}</version>
    <exclusions>
        <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
    </exclusions>
</dependency>    

 

Guess you like

Origin www.cnblogs.com/xfearless/p/log4j.html