I am going through the post jetty logging and trying to figure out what is meaning of every attribute that prints
123.4.5.6 - - [27/Aug/2004:10:16:17 0000] "GET /jetty/tut/XmlConfiguration.html HTTP/1.1" 200 76793 "http://localhost:8080/jetty/tut/logging.html" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8"
I am got the answers for some but still not able to figure out for some as mentioned below.
- 123.4.5.6 : request.getRemoteAddr()
- dash(-) : not able to figure out
- dash(-) : not able to figure out
- [27/Aug/2004:10:16:17 0000] : timestamp
- GET : request.getMethod()
- jetty/tut/XmlConfiguration.html : request.getRequestURI()
- HTTP/1.1 : request.getProtocol()
- 200 : response.getStatus()
- 76793 : response.getHttpChannel().getBytesWritten()
- http://localhost:8080/jetty/tut/logging.html : not able to figure out
- Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8 : request.getHeader("User-Agent")
Please correct me if I am wrong for other attributes as well.
CodePudding user response:
Jetty logs in the NCSA format by default. According to that,
- (2) would be the RFC 931 "remote log name of the user"
- (3) would be the "The username as which the user has authenticated himself"
Not sure, but I don't think that any of these will have a value anytime.
- (10) this is the referrer (the page which led to this request via a hyperlink), the data is in the header - see Stack Overflow question 2648984
CodePudding user response:
Recent versions of Jetty log requests with the CustomRequestLog
format.
Which has 2 default "NCSA" formats for output (along with a few others and the ability to customize the format)
NCSA_FORMAT
- syntax declaration of"%{client}a - %u %t \"%r\" %s %O"
EXTENDED_NCSA_FORMAT
- syntax ofNCSA_FORMAT
" \"%{Referer}i\" \"%{User-Agent}i\""
So, according to the documentation on CustomRequestLog
, that means that the following output ...
123.4.5.6 - - [27/Aug/2004:10:16:17 0000] "GET /jetty/tut/XmlConfiguration.html HTTP/1.1" 200 76793 "http://localhost:8080/jetty/tut/logging.html" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8"
is actually one of the extended NCSA formats.
Broken down like this ...
123.4.5.6
: the%{client}a
which is therequest.getRemoteHost()
-
: the-
a hardcoded string of-
in Jetty, that entry would have been the "remote log name user", but since Jetty doesn't support identd, we don't have a means to fill this value out (identd is old school tech that never saw a big adoption for http)-
: the%u
which is the authenticated user name, which comes from Jetty internal APIs (eg:Request.getAuthentication()
orAuthentication.getUserIdentity()
- this only works if your webapp is using Servlet security / authentication / authorization - custom authentication techniques will not have this entry filled out.[27/Aug/2004:10:16:17 0000]
: the%t
which is the Jetty APIRequest.getTimeStamp()
which is set in stone when the request was finished being parsed, but before its dispatched to a handler or webapp for processing."GET /jetty/tut/XmlConfiguration.html HTTP/1.1"
: the\"%r\"
which is the raw "Request Line" used in HTTP. Which is the first line of the HTTP request. (orrequest.getMethod()
request.getOriginalURI()
request.getProtocol()
)200
: the%s
which is the status as committed on the response obtained from the Jetty internal APIresponse.getCommittedMetadata().getStatus()
(this API exists because theHttpServletResponse
is mutable, and many webapps tend to modify it after it's been sent which would mean we log a value that wasn't actually sent if we used the standard servlet API here)76793
: the%O
which is the bytes sent on the network as part of the response which comes from the Jetty internal APIsresponse.getHttpChannel().getBytesWritten()
"http://localhost:8080/jetty/tut/logging.html"
: the\"%{Referer}i\"
which is requestReferer
line (yes, it's spelled incorrectly, but there's ancient HTTP history here for why that's the case). It comes fromrequest.getHeader("Referer")
, which can be empty in many cases."Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040614 Firefox/0.8"
: the\"%{User-Agent}i\"
is the same as above, but for theUser-Agent
request header.
You can customize this output in countless ways, just read the CustomRequestLog
apidoc and create a format of your own that has what you want and/or what you are looking for.