Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3629

No properties lookup from JsonTemplateLayout pattern resolver?

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.19.0
    • None
    • JsonTemplateLayout

    Description

      This is a slightly similar issue to LOG4J2-3367:

      I want to be able to "share" some pattern settings between a line-based logger and a JSON logger, so I created a naive config like this (both logging to console just for demo purposes):
       

      log4j2.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <Configuration name="Demo" status="debug" monitorInterval="60">
        <Properties>
          <Property name="exFilters">org.junit,org.apache.maven,sun.reflect,java.lang.reflect</Property>
          <Property name="exPattern">%xEx{filters(${exFilters})}</Property>
          <Property name="logPattern">%d{ISO8601} %-5p [%c{1}] %m%n${exPattern}</Property>
        </Properties>
        <Appenders>
          <Console name="Json">
            <JsonTemplateLayout eventTemplateUri="classpath:MyLayout.json" />
          </Console>
          <Console name="Plain">
            <PatternLayout pattern="${logPattern}" />
          </Console>
        </Appenders>
        <Loggers>
          <Root level="info">
            <AppenderRef ref="Json" />
            <AppenderRef ref="Plain" />
          </Root>
        </Loggers>
      </Configuration>

      MyLayout.json

      {
        "msg": {
          "$resolver": "message"
        },
        "thrown": {
          "stackTrace": {
            "$resolver": "pattern",
            "pattern": "${exPattern}"
          }
        }
      } 

      This doesn't work (probably because the lookup is only done at logging time, not at configuration time), but I'm wondering if this (or something similar) could be implemented somehow...

      Yes, I'm aware that ExceptionResolver provides something similar, but it's not quite the same as the %xEx pattern, which seems to be a lot more customizable...

      Attachments

        Activity

          People

            vy Volkan Yazici
            tgr Tobias Gruetzmacher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: