如何实现Log4j2自定义布局yaml配置

时间:2016-11-23 14:26:14

标签: log4j2

我正在使用log4j2框架的自定义布局。如何在log4j2 yaml配置文件中指定自定义布局? 我试过的样品如下。目前这说无效元素'布局'不起作用。

Configutation:
  status: warn
  packages: uk.co.logging.layout

  Properties:
    Property:
      name: logging.dir
      value: ./default_log_dir/
    Property:
      name: service.name
      value: default

  Appenders:
    Console:
      name: CONSOLE
      layout: ConnectJsonLayout

      policies:
        TimeBasedTriggeringPolicy:
          interval: 1
          modulate: true
        SizeBasedTriggeringPolicy:
          size: 250MB
    RollingFile:
      - name: APPLICATION
        fileName: ${logging.dir}/${service.name}.log
        filePattern: ${logging.dir}/${date:yyyy-MM}/${service.name}-%d{yyyy-MM-dd}-%i.log.gz
        layout: ConnectJsonLayout

        policies:
          TimeBasedTriggeringPolicy:
            interval: 1
            modulate: true
          SizeBasedTriggeringPolicy:
            size: 250MB

  Loggers:
      Root:
        level: error
        AppenderRef:
          - ref: CONSOLE
          - ref: APPLICATION
      Logger:
        - name: uk.co.xxx
          additivity: false
          level: debug
          AppenderRef:
            - ref: CONSOLE
            - ref: APPLICATION

亲切的问候,

基兰

1 个答案:

答案 0 :(得分:0)

Configutation:
  status: warn
  packages: uk.co.logging.layout

  Properties:
    Property:
      name: logging.dir
      value: ./default_log_dir/
    Property:
      name: service.name
      value: default

  Appenders:
    Console:
      name: CONSOLE
      ConnectJsonLayout: {}
  Loggers:
    Root:
      level: error
      AppenderRef:
        - ref: CONSOLE