[ https://issues.apache.org/jira/browse/LOG4J2-3629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17631071#comment-17631071 ]
Tobias Gruetzmacher commented on LOG4J2-3629: --------------------------------------------- Thanks for the detailed answer! Gives me some things to think about :D Regarding suppression/truncation of stack frames: Unfortunately, both implementations are not created equal, which is why I went looking for an alternative to the exception resolver: - {{filter()}} in {{ExtendedThrowablePatternConverter}} only removes the frames starting with the package, whereby the exception resolver truncates the stacktrace at the match point, throwing away everything after that... - The {{ExtendedThrowablePatternConverter}} adds location information to all stack frames, a feature completely missing from the exception resolver... Here is an example from both for comparison: {noformat} org.apache.commons.mail.EmailException: Sending the email to the following server failed : localhost:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469) ~[commons-email-1.5.jar:1.5] at org.apache.commons.mail.Email.send(Email.java:1496) ~[commons-email-1.5.jar:1.5] at com.example.demo.MailSender.sendMail(MailSender.java:24) ~[classes/:?] at com.example.demo.MailSenderLoggingTest.sendMail(MailSenderLoggingTest.java:9) ~[test-classes/:?] ... suppressed 31 lines at java.util.ArrayList.forEach(ArrayList.java:1259) ~[?:1.8.0_352] ... suppressed 9 lines at java.util.ArrayList.forEach(ArrayList.java:1259) ~[?:1.8.0_352] ... suppressed 22 lines at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:98) ~[.cp/:?] at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40) ~[.cp/:?] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529) ~[.cp/:?] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756) ~[.cp/:?] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452) ~[.cp/:?] at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210) ~[.cp/:?] Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout 60000 at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118) ~[javax.mail-1.5.6.jar:1.5.6] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:388) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:246) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:195) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Transport.send0(Transport.java:254) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Transport.send(Transport.java:124) ~[javax.mail-1.5.6.jar:1.5.6] at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459) ~[commons-email-1.5.jar:1.5] ... 73 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[?:1.8.0_352] at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[?:1.8.0_352] at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[?:1.8.0_352] at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[?:1.8.0_352] at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[?:1.8.0_352] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[?:1.8.0_352] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:1.8.0_352] at java.net.Socket.connect(Socket.java:607) ~[?:1.8.0_352] at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:329) ~[javax.mail-1.5.6.jar:1.5.6] at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:217) ~[javax.mail-1.5.6.jar:1.5.6] at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2084) ~[javax.mail-1.5.6.jar:1.5.6] at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:388) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:246) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Service.connect(Service.java:195) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Transport.send0(Transport.java:254) ~[javax.mail-1.5.6.jar:1.5.6] at javax.mail.Transport.send(Transport.java:124) ~[javax.mail-1.5.6.jar:1.5.6] at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459) ~[commons-email-1.5.jar:1.5] ... 73 more {noformat} vs. {noformat} org.apache.commons.mail.EmailException: Sending the email to the following server failed : localhost:465 at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1469) at org.apache.commons.mail.Email.send(Email.java:1496) at com.example.demo.MailSender.sendMail(MailSender.java:24) at com.example.demo.MailSenderLoggingTest.sendMail(MailSenderLoggingTest.java:9) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit ... [truncated] Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: localhost, 465; timeout 60000; nested exception is: java.net.ConnectException: Connection refused: connect at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712) at javax.mail.Service.connect(Service.java:388) at javax.mail.Service.connect(Service.java:246) at javax.mail.Service.connect(Service.java:195) at javax.mail.Transport.send0(Transport.java:254) at javax.mail.Transport.send(Transport.java:124) at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1459) ... 73 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:607) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:329) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:217) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2084) ... 80 more {noformat} (To be fair, the example from ExtendedThrowablePatternConverter seems to also suffer from LOG4J2-2092...) > 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)