A. Prepare the Logback package into the $jetty_home/lib/ext
-rw-r--r--1 conversant conversant 93525 Apr 2 logback-access-1.1.2. jar-rw-r--r--1 Conversant conversant 270747 Apr 2 logback-classic-1.1.2. Jar-rw-r--r--1 conversant Conversant 427729 Apr 2 Logback-core-1.1.2.jar
two. Configure Logback-access.xml and save
<?XML version= "1.0" encoding= "UTF-8"?><Configuration> <Statuslistenerclass= "Ch.qos.logback.core.status.OnConsoleStatusListener" /> <Appendername= "FILE"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <Filenamepattern>${log.home}/requests/%d{yyyy-mm-dd}_request.log</Filenamepattern> </Rollingpolicy> <Encoder> <pattern>Combined</pattern> </Encoder> </Appender> <Appendername= "All_requests"class= "Ch.qos.logback.core.rolling.RollingFileAppender"> <Encoder> <pattern>[%t]-%fullrequest-%fullresponse</pattern> </Encoder> <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <Filenamepattern>${log.home}/requests/%d{yyyy-mm-dd}_all.log</Filenamepattern> </Rollingpolicy> </Appender> <Appender-refref= "All_requests"/> <Appender-refref= "FILE"/></Configuration>
three. Load using Logback-access.xml
For example: Jetty-requestlog-logback.xml, the specific contents are as follows:
<?XML version= "1.0"?><!DOCTYPE Configure Public "-//jetty//configure//en" "Http://www.eclipse.org/jetty/configure_9_0.dtd"><!-- =============================================================== -<!--Configure the Jetty Request Log -<!-- =============================================================== -<ConfigureID= "Server"class= "Org.eclipse.jetty.server.Server"> <!-- =========================================================== - <!--Configure Request Log - <!-- =========================================================== - <RefrefID= "Handlers"> <Pagername= "AddHandler"> <Arg> <NewID= "Requestlog"class= "Org.eclipse.jetty.server.handler.RequestLogHandler"> <Setname= "Requestlog"> <NewID= "Requestlogimpl"class= "Ch.qos.logback.access.jetty.RequestLogImpl"> <Setname= "FileName">/opt/app/xxxx/server/conf/logback-access.xml</Set> </New> </Set> </New> </Arg> </Pager> </Ref></Configure>
Four. Configure Teefilter, print all_requests
Path: Webapp/web.xml, add the following code
<Filter> <Filter-name>Teefilter</Filter-name> <Filter-class>Ch.qos.logback.access.servlet.TeeFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Teefilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
Five. Set Startup Scripts
Modify the Jetty_args parameter to load the Jetty-requestlog-logback.xml file
jetty_args= "lib= $JETTY _home/lib $APP _home/conf/jetty/jetty.xml $APP _home/conf/jetty/jetty-requestlog-logback.xml Options=jsp "
Six. Restart and view all logs
CD ${log.home}/requests View the ${yyyy-mm-dd}_all.log file to see the full log of the output
Summary
This configuration is appropriate for all requests that need to go back to HTTP. However, for productivity and storage space issues in the online production environment, you need to turn off this configuration
Jetty Print all request log with Logback