[ 
https://issues.apache.org/jira/browse/LOG4J2-3629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tobias Gruetzmacher updated LOG4J2-3629:
----------------------------------------
    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:

 

*log4j2.xml*
{code:java}
<?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>{code}
*MyLayout.json*
{code:java}
{
  "msg": {
    "$resolver": "message"
  },
  "thrown": {
    "stackTrace": {
      "$resolver": "pattern",
      "pattern": "${exPattern}"
    }
  }
} {code}
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...

  was:
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:

 

*log4j2.xml*
{code:java}
<?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>{code}
*MyLayout.json*
{code:java}
{
  "msg": {
    "$resolver": "message"
  },
  "thrown": {
    "stackTrace": {
      "$resolver": "pattern",
      "pattern": "${exPattern}"
    }
  }
} {code}
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...


> No properties lookup from JsonTemplateLayout pattern resolver?
> --------------------------------------------------------------
>
>                 Key: LOG4J2-3629
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3629
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: JsonTemplateLayout
>    Affects Versions: 2.19.0
>            Reporter: Tobias Gruetzmacher
>            Priority: Minor
>              Labels: pattern
>
> 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:
>  
> *log4j2.xml*
> {code:java}
> <?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>{code}
> *MyLayout.json*
> {code:java}
> {
>   "msg": {
>     "$resolver": "message"
>   },
>   "thrown": {
>     "stackTrace": {
>       "$resolver": "pattern",
>       "pattern": "${exPattern}"
>     }
>   }
> } {code}
> 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...



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to