I would like to print the stack trace for the exception that was caught by pages.xml, but I only want to do so if the most granular logging level is more granular than warn
. This way, testers can copy/paste the stack trace, but end users will never see it.
Environment details:
- IBM WebSphere Application Server 7 (logging level details)
- JBoss Seam 2.2.0.GA
- JSF Facelets 1.1.15
- Logback 0.9.21
Here's how exceptions are currently being handled...
From pages.xml:
<?xml version="1.0" encoding="UTF-8"?>
<pages xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
<!-- ... -->
<exception class="javax.faces.application.ViewExpiredException">
<end-conversation />
<redirect view-id="/exceptionSessionTimeout.xhtml" />
</exception>
<!--
Prevent the Facelets error page from appearing.
This is where I want to conditionally print the stack trace.
Currently it's more or less just a generic error page.
-->
<exception>
<end-conversation />
<redirect view-id="/exception.xhtml" />
</exception>
</pages>
From web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- ... -->
<!-- Fallback static HTML page -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/unhandledException.html</location>
</error-page>
</web-app>
From logback.xml:
<?xml version="1.0" encoding="UTR-8"?>
<configuration scan="true">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%date] [%thread] [%level] [%mdc] [%logger:%method:%line]: %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/path/to/app-logs-dir/AppName.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/path/to/app-logs-dir/AppName.%d{yyyy-MM-dd-a}.gz</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>[%date] [%thread] [%level] [%mdc] [%logger:%method:%line]: %msg%n</pattern>
</encoder>
</appender>
<logger name="com.example" level="trace" />
<logger name="com.example.auth" level="error" />
<root level="warn">
<appender-ref ref="FILE" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
With the ideal solution to this problem, this would cause a stack trace to be printed on /error.xhtml (from pages.xml):
<logger name="com.example" level="trace" />
Whereas this would not:
<logger name="com.example" level="warn" />
Using Facelets with Seam, is there a way to determine Logback's log levels?