開啟JBoss7/WildFly的access_log功能

來源:互聯網
上載者:User

前言

對於一個網站來說,訪問日誌,即access_log,對網站來說是一項很重要的功能。利用它,我們可以統計出很多有用的資訊,從而給網站的營運帶來方便,所以基本上每個網站都會開啟這件功能。

JBoss As 7配置

在預設的情況下,JBoss7.1是沒有開啟access_log的,如果要開啟這項功能,就需要修改$JBOSS_HOME\standalone\configuration\standalone.xml(domain.xml)這個檔案,相關的修改內容如下所示:

<subsystem xmlns="urn:jboss:domain:web:1.0"default-virtual-server="default-host">
<connector name="http"scheme="http" protocol="HTTP/1.1" socket-binding="http"/>
<virtual-server name="default-host" enable-welcome-root="true">
<alias name="localhost"/>
<alias name="example.com"/>
<access-log/>
</virtual-server>
</subsystem>

當完成上面的配置並重啟伺服器後,你就可以訪問一下你的網站,然後你就會在$JBOSS_HOME\standalone\log\default-host目錄下看到一個名為access_log.2012-02-24的檔案,它就是你所需要的訪問日誌了。

WildFly 8 配置

WildFly開啟access_log的方法和JBoss 7 類似,也是找到相對應的web容器添加上配置就可以了,只不過二者使用的容器不相同,而且WildFly中必須指定log的存放目錄。


<subsystem xmlns="urn:jboss:domain:undertow:1.0">
<buffer-caches>
<buffer-cache name="default" buffer-size="1024" buffers-per-region="1024" max-regions="10"/>
</buffer-caches>
<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>
<servlet-container name="default" default-buffer-cache="default" stack-trace-on-error="local-only">
<jsp-config/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content" directory-listing="true"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="Wildfly 8"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow 1"/>
</filters>
</subsystem>

如上,添加紅色標記一行,即可開啟WildFly 8的access_log功能,重啟伺服器,訪問ip:8080即可在JBOSS_HOME/standalone/log目錄下產生access.log

其中

prefix指定log檔案的首碼名即檔案名稱

pattern指定日誌的格式

pattern可以設定成兩種方式,第一種是pattern="common",第二種是pattern="combined"

以下是筆者測試的兩種格式的日誌輸出,訪問localhost:8080

common格式的日誌輸出如下:

combined格式的日誌輸出如下:<喎?http://www.bkjia.com/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+CjxzdHJvbmc+PGltZyBjbGFzcz0="confluence-embedded-image" src="http://wiki.cnsuning.com/download/attachments/16617941/access1.PNG?version=1&modificationDate=1392710363718&api=v2" alt="">

可以看出,第二種格式的日誌輸出相對具體,而實際開發過程中開啟哪種格式的access_log要根據需求來確定就可以了。

結束語

開啟access_log的配置到此結束,若有問題,請參考以下資料,或者直接聯絡我們,謝謝!

參考資料

https://issues.jboss.org/browse/WFLY-1721

http://hi.baidu.com/saiv000/item/9ed9779aa1b1a2dc1f4271ea

http://hooray520.iteye.com/blog/1335156

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.