JBOSS jboss-log4j.xml文件中配置web工程日志

如果使用log4j日志框架,将配置文件放在工程目录下的话容易引起与jboss日志配置的冲突,一个比较好的方式就是将日志配置到jboss的 jboss-log4j.xml文件中,文件的目录是($JBOSS)/server/default/conf。在配置文件中添加以下内容:

<appender name="myLog" class="org.apache.log4j.DailyRollingFileAppender">
    <!--设置通道名称是:file,输出方式DailyRollingFileAppender-->
    <param name="File" value="${jboss.server.home.dir}/log/Mqs.log"/>
    <!--日志文件路径和文件名称 -->
  
    <param name="Append" value="true"/>
    <!-- 设置是否在重新启动服务时,在原有日志的基础添加新日志 -->

    <!-- Rollover at midnight each day -->
    <param name="DatePattern" value="'.'yyyy-MM-dd"/>

  
    <!-- Rollover at the top of each hour
    <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
    -->
    <layout class="org.apache.log4j.PatternLayout">
      <!-- The default pattern: Date Priority [Category] Message/n -->
      <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
      <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message/n
      <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
       -->
    </layout>    
  </appender>

  <logger name="com.all" additivity="false" >
    <level value="INFO" />
    <appender-ref ref="myLog"/>
  </logger>

在web工程中使用日志的时候就可以这样写

Logger log = Logger.getLogger("com.all");

log.debug("test");

其中"com.all"与<logger name="com.all" additivity="false" > 中的name属性值对应。additivity属性非常重要,它表示是否继承root配置的输出通道,默认配置是true,如果不将其设为false的话 会导致日志重复输出到控制台与jboss的日志文件中。

deploy/jbossweb-tomcat55.sar/server.xml <Valve className="org.apache.catalina.valves.FastCommonAccessLogValve" prefix="access_log." suffix=".log" pattern="%h %t %r %s %D" directory="${jboss.server.home.dir}/../output/logs" resolveHosts="false" /> http://tomcat.apache.org/tomcat-5.5-doc/config/valve.html pattern配置: %a - Remote IP address %A - Local IP address %b - Bytes sent, excluding HTTP headers, or '-' if zero %B - Bytes sent, excluding HTTP headers %h - Remote host name (or IP address if resolveHosts is false) %H - Request protocol %l - Remote logical username from identd (always returns '-') %m - Request method (GET, POST, etc.) %p - Local port on which this request was received %q - Query string (prepended with a '?' if it exists) %r - First line of the request (method and request URI) %s - HTTP status code of the response %S - User session ID %t - Date and time, in Common Log Format %u - Remote user that was authenticated (if any), else '-' %U - Requested URL path %v - Local server name %D - Time taken to process the request, in millis %T - Time taken to process the request, in seconds %I - current request thread name (can compare later with stacktraces) There is also support to write information from the cookie, incoming header, outgoing response headers, the Session or something else in the ServletRequest. It is modeled after the apache syntax: %{xxx}i for incoming request headers %{xxx}o for outgoing response headers %{xxx}c for a specific request cookie %{xxx}r xxx is an attribute in the ServletRequest %{xxx}s xxx is an attribute in the HttpSession The shorthand pattern name common (which is also the default) corresponds to '%h %l %u %t "%r" %s %b'.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值