how to modify the pattern of access_log on wildfly
hai_feng Jun 24, 2014 10:33 PMHello everybady
We all know that we can open access_log on wildfly by following configuration:
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
<access-log pattern="common" directory="${jboss.home.dir}/standalone/log" prefix="access" />
</host>
</server>
there are two pattern of access_log,one is common,the other is combined.
the commom pattern is "%h %l %u %t "%r" %s %b"
the combined pattern is "%h %l %u %t "%r" %s %b "%{i,Referer}" "%{i,User-Agent}""
Now i want to modify the pattern to "%h\t%{x-forwarded-for}i\t%l\t%u\t%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t\t%m\t\"%U\"\t\"%q\"\t%H\t%>s\t%b\t%D\t\"%{Referer}i\"\t\"%{User-Agent}i\"\t%{Cdn-Src-Ip}i\t%V\t%v\t%A\t%X\tV4"
who can tell me the way?
I try to modify the sources of undertow,i modify the class AccessLogHandler under pakage:io.undertow.server.handlers.accesslog.
in this case,i want to modify pattern of common to "%h\t%{x-forwarded-for}i\t%l\t%u\t%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t\t%m\t\"%U\"\t\"%q\"\t%H\t%>s\t%b\t%D\t\"%{Referer}i\"\t\"%{User-Agent}i\"\t%{Cdn-Src-Ip}i\t%V\t%v\t%A\t%X\tV4" directly.
private static String handleCommonNames(String formatString) { if(formatString.equals("common")) { return "%h\t%{x-forwarded-for}i\t%l\t%u\t%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t\t%m\t\"%U\"\t\"%q\"\t%H\t%>s\t%b\t%D\t\"%{Referer}i\"\t\"%{User-Agent}i\"\t%{Cdn-Src-Ip}i\t%V\t%v\t%A\t%X\tV4"; } else if (formatString.equals("combined")) { return "%h %l %u %t \"%r\" %s %b \"%{i,Referer}\" \"%{i,User-Agent}\""; } return formatString; }
rebuild it and replace the class to wildfly.but when i visit localhost:8080,the access_log print as follow:
10.22.4.46 | %{x-forwarded-for}i | - | - | %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t | GET | "/" | "-" | HTTP/1.1 | %>s | 2304 | - | "%{Referer}i" | "%{User-Agent}i" | %{Cdn-Src-Ip}i | %V | 10.22.4.46:8080 | 10.22.4.46 | %X | V4 |
10.22.4.46 | %{x-forwarded-for}i | - | - | %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t | GET | "/wildfly_logo.png" | "-" | HTTP/1.1 | %>s | 21247 | - | "%{Referer}i" | "%{User-Agent}i" | %{Cdn-Src-Ip}i | %V | 10.22.4.46:8080 | 10.22.4.46 | %X | V4 |
10.22.4.46 | %{x-forwarded-for}i | - | - | %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t | GET | "/wildfly.css" | "-" | HTTP/1.1 | %>s | 1687 | - | "%{Referer}i" | "%{User-Agent}i" | %{Cdn-Src-Ip}i | %V | 10.22.4.46:8080 | 10.22.4.46 | %X | V4 |
10.22.4.46 | %{x-forwarded-for}i | - | - | %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t | GET | "/suning_logo.png" | "-" | HTTP/1.1 | %>s | 8566 | - | "%{Referer}i" | "%{User-Agent}i" | %{Cdn-Src-Ip}i | %V | 10.22.4.46:8080 | 10.22.4.46 | %X | V4 |
10.22.4.46 | %{x-forwarded-for}i | - | - | %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t | GET | "/favicon.ico" | "-" | HTTP/1.1 | %>s | 1150 | - | "%{Referer}i" | "%{User-Agent}i" | %{Cdn-Src-Ip}i | %V | 10.22.4.46:8080 | 10.22.4.46 | %X | V4 |
we can see that there no value of %{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}t,so this way does work.
what can i do? i look foreware to your help!
thanks!