16,添加项目日志2

1, 在source文件夹下面创建 log4j2.yml
内容如下

Appenders:
    Console:  #输出到控制台
      name: CONSOLE #Appender命名
      target: SYSTEM_OUT
      PatternLayout:
        pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"
    RollingFile: # 输出到文件,超过256MB归档
  - name: ROLLING_FILE
        ignoreExceptions: false
        fileName: /var/log/log4j/sd-cms.log
        filePattern: "/var/log/log4j/$${date:yyyy-MM}/sd-cms -%d{yyyy-MM-dd}-%i.log.gz"
        PatternLayout:
   pattern: "%d{yyyy-MM-dd HH:mm:ss,SSS}:%4p %t (%F:%L) - %m%n"
        Policies:
          SizeBasedTriggeringPolicy:
            size: "256 MB"
        DefaultRolloverStrategy:
          max: 1000
Loggers:
  Root:
      level: info
      AppenderRef:
        - ref: CONSOLE
    Logger: #单独设置某些包的输出级别
      - name: com.sd.cms.mapper #复数加上-
        additivity: false #去除重复的log
        level: trace
        AppenderRef:
          - ref: CONSOLE #复数加上-
          - ref: ROLLING_FILE #复数加上-

2,添加jar


        
            org.springframework.boot
            spring-boot-starter-log4j2
            1.5.6.RELEASE
        
                     
            com.fasterxml.jackson.dataformat
            jackson-dataformat-yaml
        













你可能感兴趣的:(16,添加项目日志2)