【问题标题】:tomcat access log get my eth0 ip?tomcat访问日志获取我的eth0 ip?
【发布时间】:2017-03-29 03:05:09
【问题描述】:
<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:36: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) 壁虎/20100101 火狐/52.0 -

在 server.xml %A 中只给我循环 ip,但我想要 eth0 ip ..

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

【问题讨论】:

    标签: linux tomcat access-log


    【解决方案1】:
    1. 检查主机名:
    $ hostname
    yourhost
    
    1. 编辑 /etc/hosts 并添加:
    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);
        }
    }
    

    【讨论】:

    • 应用更改后您是否重新启动了 Tomcat?
    • 最近比较忙,没时间回复,不好意思。问题已解决。谢谢。
    猜你喜欢
    • 2018-01-14
    • 2017-11-25
    • 2014-06-29
    • 1970-01-01
    • 2017-08-13
    • 2020-08-21
    • 2011-11-27
    • 2020-05-22
    • 1970-01-01
    相关资源
    最近更新 更多