1 Reply Latest reply on Sep 6, 2014 9:38 AM by japearson

    how to modify the pattern of access_log on wildfly

    hai_feng

      Hello 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}tGET"/""-"HTTP/1.1%>s2304-"%{Referer}i""%{User-Agent}i"%{Cdn-Src-Ip}i%V10.22.4.46:808010.22.4.46%XV4
      10.22.4.46%{x-forwarded-for}i--%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}tGET"/wildfly_logo.png""-"HTTP/1.1%>s21247-"%{Referer}i""%{User-Agent}i"%{Cdn-Src-Ip}i%V10.22.4.46:808010.22.4.46%XV4
      10.22.4.46%{x-forwarded-for}i--%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}tGET"/wildfly.css""-"HTTP/1.1%>s1687-"%{Referer}i""%{User-Agent}i"%{Cdn-Src-Ip}i%V10.22.4.46:808010.22.4.46%XV4
      10.22.4.46%{x-forwarded-for}i--%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}tGET"/suning_logo.png""-"HTTP/1.1%>s8566-"%{Referer}i""%{User-Agent}i"%{Cdn-Src-Ip}i%V10.22.4.46:808010.22.4.46%XV4
      10.22.4.46%{x-forwarded-for}i--%{%Y-%m-%d %H:%M:%S}t.%{%msec}t %{%z}tGET"/favicon.ico""-"HTTP/1.1%>s1150-"%{Referer}i""%{User-Agent}i"%{Cdn-Src-Ip}i%V10.22.4.46:808010.22.4.46%XV4

       

      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!