How to add the date timestamp to log4j2 logfiles?

前端 未结 5 1950
无人及你
无人及你 2021-02-14 04:03

I want to create day dependent logfiles with log4j2:


<
5条回答
  •  旧时难觅i
    2021-02-14 04:35

    In yaml check the Property filePattern defined as "${date:yyyy-MM-dd}", which helps to tag the date. If you are interested to tag the HOSTNAME environment variable to date then : "${env:HOST}-${date:yyyy-MM-dd}"

    Properties:
        Property:
          - name: log-path
            value: "logs"
          - name:  filePattern
            value: "${date:yyyy-MM-dd}"
    
      Appenders:
    
        Console:
          name: Console_Appender
          target: SYSTEM_OUT
          PatternLayout:
            pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
    
        File:
          name: File_Appender
          fileName: "${log-path}/filelog-${filePattern}.log"
    
          PatternLayout:
            pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
    
        RollingFile:
          - name: RollingFile_Appender
            fileName: "${log-path}/rollingfile-${filePattern}.log"
            filePattern: "logs/archive/rollingfile.log.%d{yyyy-MM-dd-hh-mm}.gz"
            PatternLayout:
              pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
    

提交回复
热议问题