You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Volkan Yazici (Jira)" <ji...@apache.org> on 2022/11/08 20:56:00 UTC
[jira] [Assigned] (LOG4J2-3629) No properties lookup from JsonTemplateLayout pattern resolver?
[ https://issues.apache.org/jira/browse/LOG4J2-3629?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Volkan Yazici reassigned LOG4J2-3629:
-------------------------------------
Assignee: Volkan Yazici
> 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
> Assignee: Volkan Yazici
> 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 (both logging to console just for demo purposes):
>
> *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)