Disable call stacks for errors in log?

Hi,
it may be a stupid question, but I could not find a way to solve this: I repeatedly get error messages in openhab.log for various reasons (which I hope to find some day and eliminate them all). The problem is that with each error the whole java call stack is usually included, like

2021-07-23 16:37:18.897 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
        at org.apache.cxf.jaxrs.utils.SpecExceptions.toNotSupportedException(SpecExceptions.java:109)
        at org.apache.cxf.jaxrs.utils.ExceptionUtils.toNotSupportedException(ExceptionUtils.java:160)
        at org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:383)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
        at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:78)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)
        at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:216)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:301)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:220)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
....

and so on. The call stack, not just quite unhelpful for debugging, is often very long, flooding the logs, causing huge log files of which I am really annoyed by now.
I wonder if there is a way to disable the inclusion of call stacks for the errors?
(I do not wish to disable any error messages, just want them to take no more than a single line in the logfile, so the above example would be no more than
2021-07-23 16:37:18.897 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.NotSupportedException: HTTP 415 Unsupported Media Type
)
Is this possible somehow?

According to logging - How can I configure log4j to not print the exception stacktrace? - Stack Overflow it should be possible by configuring log4j.

One of the suggestions is to use %ex{0} in log4j configuration. See also
http://logback.qos.ch/manual/layouts.html#ex

1 Like

Thanks, this should be exactly what I need! I just wonder where does the exception keyword need to be added precisely in OH3? I tried to add it to the end of the openhab.log <RollingFile ...> section of /var/lib/openhab/etc/log4j2.xml as

<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n%ex{short}"/>

but no lock so far. (Sorry I am not quite familiar with log4j yet.)

 <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%-5.5p] [%-36.36c] - %m%n%ex{short}"/>

I think the configuration is not correct you need to use %ex{short} instead /in-place of %m
What just tried it:

  • stop openhab serivce ( sudo service openhab stop )
  • edit log4j2.xml
  • started the service again ( sudo service openhab start )

The results are for %m%n

2021-07-24 19:55:52.567 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Time zone set to 'Europe/Berlin'.
2021-07-24 19:55:52.629 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Location set to 'XX.XXXX38937470486,XX.XXXX95313644411'.
2021-07-24 19:55:52.640 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Locale set to 'de_DE'.
2021-07-24 19:55:52.648 [INFO ] [.core.internal.i18n.I18nProviderImpl] - Measurement system set to 'SI'.
2021-07-24 19:56:01.330 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network-devices.items'
2021-07-24 19:56:01.885 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.items'
2021-07-24 19:56:02.665 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network-devices.things'
2021-07-24 19:56:02.767 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.things'
2021-07-24 19:56:02.800 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'gmail.things'
2021-07-24 19:56:05.273 [INFO ] [.core.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2021-07-24 19:56:07.817 [INFO ] [org.openhab.ui.internal.UIService   ] - Started UI on port 8080
2021-07-24 19:56:08.381 [INFO ] [ternal.dhcp.DHCPPacketListenerServer] - DHCP request packet listener online
2021-07-24 19:56:10.201 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Started HABPanel at /habpanel
2021-07-24 19:56:11.130 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab/addons/mssql-jdbc-9.2.1.jre11.jar
org.osgi.framework.BundleException: Could not resolve module: com.microsoft.sqlserver.mssql-jdbc [220]
  Unresolved requirement: Import-Package: com.azure.core.credential; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.core.http; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.core.http.policy; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.core.util; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.identity; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.security.keyvault.keys; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.security.keyvault.keys.cryptography; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.security.keyvault.keys.cryptography.models; resolution:="optional"
  Unresolved requirement: Import-Package: com.azure.security.keyvault.keys.models; resolution:="optional"
  Unresolved requirement: Import-Package: com.microsoft.aad.msal4j; version="[1.7.0,2.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.antlr.v4.runtime; version="[4.7.0,5.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.antlr.v4.runtime.atn; version="[4.7.0,5.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.antlr.v4.runtime.dfa; version="[4.7.0,5.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.bouncycastle.jce.provider; version="[1.65.0,2.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.bouncycastle.openssl; version="[1.65.0,2.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.bouncycastle.openssl.jcajce; version="[1.65.0,2.0.0)"; resolution:="optional"
  Unresolved requirement: Import-Package: org.osgi.service.jdbc; version="[1.0.0,2.0.0)"

	at org.eclipse.osgi.container.Module.start(Module.java:444) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383) ~[org.eclipse.osgi-3.12.100.jar:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) [bundleFile:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) [bundleFile:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startAllBundles(DirectoryWatcher.java:1221) [bundleFile:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:515) [bundleFile:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) [bundleFile:3.6.4]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) [bundleFile:3.6.4]
2021-07-24 19:56:13.204 [INFO ] [e.automation.internal.RuleEngineImpl] - Rule engine started.
2021-07-24 19:59:28.227 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - Stopped HABPanel
2021-07-24 19:59:28.257 [INFO ] [basic.internal.servlet.WebAppServlet] - Stopped Basic UI
2021-07-24 19:59:28.431 [INFO ] [org.openhab.ui.internal.UIService   ] - Stopped UI

Result for %ex{0}%n:

2021-07-25 11:39:54.198 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:39:54.244 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:39:54.252 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:39:54.256 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:40:01.308 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:40:01.835 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:40:02.550 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:40:02.622 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:40:02.651 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:40:04.976 [INFO ] [.core.model.lsp.internal.ModelServer] - 
2021-07-25 11:40:07.444 [INFO ] [org.openhab.ui.internal.UIService   ] - 
2021-07-25 11:40:07.864 [INFO ] [ternal.dhcp.DHCPPacketListenerServer] - 
2021-07-25 11:40:09.696 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - 
2021-07-25 11:40:14.543 [INFO ] [e.automation.internal.RuleEngineImpl] - 
2021-07-25 11:40:19.276 [WARN ] [org.apache.felix.fileinstall        ] - 
2021-07-25 11:42:08.815 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - 
2021-07-25 11:42:08.851 [INFO ] [basic.internal.servlet.WebAppServlet] - 
2021-07-25 11:42:09.047 [INFO ] [org.openhab.ui.internal.UIService   ] -

Result for %ex{smart}%n:

2021-07-25 11:43:20.617 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:43:20.646 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:43:20.655 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:43:20.660 [INFO ] [.core.internal.i18n.I18nProviderImpl] - 
2021-07-25 11:43:27.164 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:43:27.656 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:43:28.391 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:43:28.471 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:43:28.506 [INFO ] [el.core.internal.ModelRepositoryImpl] - 
2021-07-25 11:43:30.825 [INFO ] [.core.model.lsp.internal.ModelServer] - 
2021-07-25 11:43:33.143 [INFO ] [org.openhab.ui.internal.UIService   ] - 
2021-07-25 11:43:33.629 [INFO ] [ternal.dhcp.DHCPPacketListenerServer] - 
2021-07-25 11:43:35.175 [INFO ] [ab.ui.habpanel.internal.HABPanelTile] - 
2021-07-25 11:43:36.061 [WARN ] [org.apache.felix.fileinstall        ] - org.osgi.framework.BundleException: Could not resolve module: com.microsoft.sqlserver.mssql-jdbc [220]
  Unresolved requirement: Import-Package: com.azure.core.credential; resolution:="optional"
2021-07-25 11:43:40.886 [INFO ] [e.automation.internal.RuleEngineImpl] -

Thanks! In your examples (also confirmed in my case) replacing %m with %ex{…} also clears all messages from the logs. This essentially renders the whole log file useless, so not quite an option. If I add %ex{short} either before or after %m, the whole stack is included anyway.
Funny is that adding %nopex - which should also disable call trace handling - results in the “opex” entry in the log (preceded by a newline). Looks like these conversion keywords do not really work here as they should. Is there perhaps some special syntax with this xml-based configuration of OH3?