This demo project shows a few things that are of use for working with logging libraries and error handling.
You will need
- Java 11+
- Maven 3.9.6+
- An unpacked
jetty-home
somewhere on your system (not within this cloned project!)
Download it and unpack it.
$ cd ~/tmp
$ curl -O http://central.maven.org/maven2/org/eclipse/jetty/jetty-home/12.0.8/jetty-home-12.0.8.tar.gz
$ tar -zxvf jetty-home-12.0.8.tar.gz
Using the above directories as an example, that means your $JETTY_HOME
is
now $HOME/tmp/jetty-home-12.0.8/
$ mvn clean install
The result is a webapp in /webapps/root.war
$ cd demobase
$ java -jar $JETTY_HOME/start.jar
Simply make requests for content against the following URLs
http://localhost:8080/normal/
- this will trigger a simple logging event from the webapp (andtext/plain
response indicating as such)http://localhost:8080/normal/naughty/
- this will trigger an unhandled exception from a webapp, causing the standard Servlet error handling to kick in
This project contains an example Jetty jetty.base
configuration.
The maven project builds a war file as normal, but has an additional step to put
that war file into demobase/webapps/logging-webapp.war
, so that the jetty.base
configuration
can use it.
logging-webapp/src/main/webapp/WEB-INF/web.xml
- this contains the servlets + error handling definitiondemobase/start.ini
- this contains thejetty.base
configuration for this instance of jetty (it has modules forhttp
,deploy
, andresources
along with manual lib entries for slf4j and log4j2)demobase/lib/slf4j/
- this is thejetty.base
server libs for slf4j, Using a version newer then what the webapp has.demobase/lib/log4j/
- this is thejetty.base
server libs for log4j, Using a version newer then what the webapp has.demobase/webapps/normal.xml
- this is the configuration used to control the classloader for the deployed webapp at the root context (context-path of/
).demobase/resources/logback.xml
- this is the server logback configurationlogging-webapp/src/main/resources/log4j2.xml
- this is the webapp log4j2 configuration (also found within thewebapps/logging-webapp.war
when compiled)