tomcat访问日志获取我的eth0 ip?

时间:2017-03-29 03:05:09

标签: linux tomcat access-log

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
       prefix="localhost_access_log" suffix=".txt"
       pattern="%t %a %A %p %r %q %s %B  %D %{User-Agent}i %{Referer}i"
       resolveHosts="false" />

这是我的server.xml,然后我发现结果是这样的:

  

[29 / Mar / 2017:10:3​​6:16 +0800] 192.168.5.149 127.0.0.1 80 GET /favicon.ico HTTP / 1.1 404 0 0 Mozilla / 5.0(Windows NT 6.1; Win64; x64; rv: 52.0)Gecko / 20100101 Firefox / 52.0 -

在server.xml%A中的

只给我循环ip,但我想要eth0 ip ..

那我该怎么办?非常感谢!

1 个答案:

答案 0 :(得分:0)

  1. 检查主机名:
  2. $ hostname
    yourhost
    
    1. 编辑/ etc / hosts并添加:
    2. 192.168.5.1    yourhost
      

      仅供参考,Tomcat源代码:

      /**
       * write local IP address - %A
       */
      protected static class LocalAddrElement implements AccessLogElement {
      
          private static final String LOCAL_ADDR_VALUE;
      
          static {
              String init;
              try {
                  init = InetAddress.getLocalHost().getHostAddress();
              } catch (Throwable e) {
                  ExceptionUtils.handleThrowable(e);
                  init = "127.0.0.1";
              }
              LOCAL_ADDR_VALUE = init;
          }
      
          @Override
          public void addElement(StringBuilder buf, Date date, Request request,
                  Response response, long time) {
              buf.append(LOCAL_ADDR_VALUE);
          }
      }