· /*
* 根据 pattern,创建以下六种类型的信息之一:
* %{xxx}i 获取header 的某个 attribute
* %{xxx}c 获取cookie 的某个 attribute
* %{xxx}o 获取response 的某个 attribute
* %{xxx}r 获取request 的某个 attribute
* %{xxx}s 获取session 的某个 attribute
* %{xxx}t 获取dateAndTime 的某个 attribute
*/
protected AccessLogElement createAccessLogElement(String attribute, char pattern) {
switch (pattern) {
case 'i':
return new HeaderElement(attribute);
case 'c':
return new CookieElement(attribute);
case 'o':
return new ResponseHeaderElement(attribute);
case 'r':
return new RequestAttributeElement(attribute);
case 's':
return new SessionAttributeElement(attribute);
case 't':
return new DateAndTimeElement(attribute);
default:
return new StringElement("???");
}
}
常规 element 的创建:
protected AccessLogElement createAccessLogElement(char pattern) {
switch (pattern) {
case 'a':
return new RemoteAddrElement();
case 'A':
return new LocalAddrElement();
case 'b':
return new ByteSentElement(true);
case 'B':
return new ByteSentElement(false);
case 'D':
return new ElapsedTimeElement(true);
case 'F':
return new FirstByteTimeElement();
case 'h':
return new HostElement();
case 'H':
return new ProtocolElement();
case 'l':
return new LogicalUserNameElement();
case 'm':
return new MethodElement();
case 'p':
return new LocalPortElement();
case 'q':
return new QueryElement();
case 'r':
return new RequestElement();
case 's':
return new HttpStatusCodeElement();
case 'S':
return new SessionIdElement();
case 't':
return new DateAndTimeElement();
case 'T':
return new ElapsedTimeElement(false);
case 'u':
return new UserElement();
case 'U':
return new RequestURIElement();
case 'v':
return new LocalServerNameElement();
case 'I':
return new ThreadNameElement();
default:
return new StringElement("???" + pattern + "???");
}
}
对于各种 element,这里只给出其中几个,其他的类似:
//accessElement 接口
protected interface AccessLogElement {
public void addElement(StringBuilder buf, Date date, Request request,
Response response, long time);
}
//sessionElement %{xxx}s
protected static class SessionAttributeElement implements AccessLogElement {
private final String header;
public SessionAttributeElement(String header) {
this.header = header;
}