在Tomcat的server.xml中,可以为service元素定义AccessLogValve吗?

huangapple go评论43阅读模式
英文:

In tomcat server.xml, can AccessLogValve be defined for service element

问题

除了代码部分,以下是翻译好的内容:

我有一个完全正常运行的Tomcat服务器,除了写访问日志之外。
在Server.xml中,访问日志定义如下:

<Server port="xxxx" shutdown="SHUTDOWN">
<GlobalNamingResources>

</GlobalNamingResources>
<Service name="Catalina">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="access." suffix=".log" pattern="common" resolveHosts="false"/>
<Connector --- />
<Connector --- />
<Executor --- />
<Engine name="Catalina" defaultHost="localhost">
<Realm ---/>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host>
</Engine>
</Service>
</Server>

我可以看到访问日志阀门是在service标签下定义的,而不是在Engine、Host或Context内部,这可能是服务器不写入访问日志的原因吗?

官方文档建议支持这种配置:https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Access_Logs

英文:

I have a tomcat server running perfectly fine apart from writing the access logs.
In Server.xml, the access log is defines like below:

     &lt;Server port=&quot;xxxx&quot; shutdown=&quot;SHUTDOWN&quot;&gt;
    &lt;GlobalNamingResources&gt;
            ----
     &lt;/GlobalNamingResources&gt;
    &lt;Service name=&quot;Catalina&quot;&gt;
            &lt;Valve className=&quot;org.apache.catalina.valves.AccessLogValve&quot; directory=&quot;logs&quot; prefix=&quot;access.&quot; suffix=&quot;.log&quot; pattern=&quot;common&quot; resolveHosts=&quot;false&quot;/&gt;
            &lt;Connector --- /&gt;
            &lt;Connector --- /&gt;
            &lt;Executor --- /&gt;
            &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot;&gt;
                    &lt;Realm ---/&gt;
                    &lt;Host name=&quot;localhost&quot;  appBase=&quot;webapps&quot; unpackWARs=&quot;true&quot; autoDeploy=&quot;true&quot; xmlValidation=&quot;false&quot; xmlNamespaceAware=&quot;false&quot;&gt;&lt;/Host&gt;
            &lt;/Engine&gt;
    &lt;/Service&gt;

</Server>

I can see that accesslog valve is defined under service tag and not inside of Engine, host or Context as per common implementation. Can this be the reason behind the server not writing access logs

Official documentation suggesting supporting this: https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Access_Logs

答案1

得分: 2

从server.xml中获得了以下注释:

> 一个“Service”是一个包含一个或多个“Connectors”的集合,它们共享
一个单独的“Container” 注意:一个“Service”本身不是一个“Container”,
因此您不能在这个级别定义诸如“Valves”之类的子组件。
文档位于/docs/config/service.html

英文:

Got this comment from server.xml :

> A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html

huangapple
  • 本文由 发表于 2020年7月22日 10:55:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/63026103.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定