如何在Wildfly上将运行时错误记录到文件中

huangapple go评论77阅读模式
英文:

How to log runtime errors on a file with wildfly

问题

我有几个具有相同groupId的Web应用程序模块部署在wildfly 18上,假设是org.foo.ecommerce

这些模块都配置了自己的子组,因此:

  1. module1 - org.foo.ecommerce.mod1
  2. module2 - org.foo.ecommerce.mod2
  3. module3 - org.foo.ecommerce.mod3

因此,我为每个模块配置了wildfly的处理程序,如下所示:

<periodic-rotating-file-handler name="MOD1_HANDLER">
    <level name="DEBUG"/>
    <encoding value="UTF-8"/>
    <formatter>
        <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] - %s%E%n"/>
    </formatter>
    <file relative-to="log.path" path="mod1.log"/>
    <suffix value=".yyyy-MM-dd"/>
</periodic-rotating-file-handler>

<logger category="org.foo.ecommerce.mod1" use-parent-handlers="false">
    <handlers>
        <handler name="MOD1_HANDLER"/>
    </handlers>
</logger>

现在,如果出现空指针异常,我只能在wildfly的server.log中找到它。

如何在属于哪个模块的所有异常上显示?

更新

这是控制台/server.log上的堆栈跟踪:

org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:82)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:346)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:193)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:456)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
    at org.jboss.resteasy.resteasy-

请注意,即使我声明了自己的异常,行为也是相同的:

@javax.ejb.ApplicationException(rollback = true)
public class ApplicationException extends RuntimeException {
}
英文:

I have several web app modules with same groupId deployed on wildfly 18, let's say org.foo.ecommerce

These modules are configured with its own subgroup , therefore:

  1. module1 - org.foo.ecommerce.mod1
  2. module2 - org.foo.ecommerce.mod2
  3. module3 - org.foo.ecommerce.mod3

So I configured wildfly with an handler for each module, like the following:

&lt;periodic-rotating-file-handler name=&quot;MOD1_HANDLER&quot;&gt;
	&lt;level name=&quot;DEBUG&quot;/&gt;
	&lt;encoding value=&quot;UTF-8&quot;/&gt;
	&lt;formatter&gt;
		&lt;pattern-formatter pattern=&quot;%d{HH:mm:ss,SSS} %-5p [%c] - %s%E%n&quot;/&gt;
	&lt;/formatter&gt;
	&lt;file relative-to=&quot;log.path&quot; path=&quot;mod1.log&quot;/&gt;
	&lt;suffix value=&quot;.yyyy-MM-dd&quot;/&gt;
&lt;/periodic-rotating-file-handler&gt;

&lt;logger category=&quot;org.foo.ecommerce.mod1&quot; use-parent-handlers=&quot;false&quot;&gt;
	&lt;handlers&gt;
		&lt;handler name=&quot;MOD1_HANDLER&quot;/&gt;
	&lt;/handlers&gt;
&lt;/logger&gt;

Now, if for some reason a NullPointerException is thrown, I can find it ONLY on wildfly server.log.

How can I display all exceptions on the module that belongs from ?

UPDATE

This is the stacktrace on console / server.log

org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:82)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:346)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:193)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:456)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
    at org.jboss.resteasy.resteasy-jaxrs@3.9.1.Final//org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
    at org.jboss.resteasy.resteasy-

Notice that even if I declare my own exception the behaviour is the same

@javax.ejb.ApplicationException(rollback = true)
public class ApplicationException extends RuntimeException {
}

答案1

得分: 1

NullPointerException总是记录到server.log的原因是因为它来自RESTEasy。任何服务器级别的模块都会按照服务器日志配置级别记录日志。如果部署创建了自己的日志配置,只有从部署中记录的日志消息会记录到该配置中。

尽管如此,存在一个未解决的问题,WFCORE-4807,它可能允许在服务器模块中创建的日志记录到部署的配置中。

英文:

The reason the NullPointerException is always logged to the server.log is because it's coming from RESTEasy. Any server level modules will log at the servers log configuration level. If a deployment creates it's own log configuration only log messages logged from the deployment are logged to that configuration.

That said there is an open issue, WFCORE-4807, which may allow logs created in server modules to be logged to a deployments configuration.

答案2

得分: 0

你最好使用每个部署的日志记录。这样,您可以获得与该部署有关的任何日志,而不仅仅是基于类的包名称的日志。

英文:

You are better to use per deployment logging. That way you get logs for anything based on that deployment, not just based on the package name of the class

huangapple
  • 本文由 发表于 2020年8月5日 18:38:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63263382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定