Jetty HTTP logging

2020-02-23 08:05发布

I would like to have Jetty log all HTTP requests (along with the body) and responses. Is this natively supported by Jetty? Ideally it would log to my existing log4j log file.

I am running Jetty 6.

2条回答
孤傲高冷的网名
2楼-- · 2020-02-23 08:20

TL;DR

You have to enable the right modules, just add into the start.ini file:

# Create access log file
--module=requestlog

# Redirect all the console log to a file
--module=console-capture

Restart Jetty and have a look into the logs directory.

查看更多
Melony?
3楼-- · 2020-02-23 08:26

Jetty comes with a request logger that can log in NCSA format. That format doesn't include things like request body as you require, but that standard format will fit tools like webalizer and the like.

If you need to log more you can use the logback request log implementation or write your own logger by implementing Jetty's RequestLog interface.

Besides that I'd highly recommend to upgrade to jetty7/8 (same codebase, but 8 provides servlet 3.0 functionality). Or directly move to jetty9.

Here's the jetty9 documentation for request logs: http://www.eclipse.org/jetty/documentation/current/configuring-logging.html#configuring-jetty-request-logs

Same for jetty7/8: http://wiki.eclipse.org/Jetty/Tutorial/RequestLog

I leave it as an exercise for you to find the jetty6 docs or better yet, upgrade. :)

Ok, just found the jetty6 docs by accident: http://docs.codehaus.org/display/JETTY/Logging+Requests

查看更多
登录 后发表回答