A log of Web applications implemented under JBoss by configuring Log4j.xml

Source: Internet
Author: User
Tags jboss jboss server log4j

Log4j is an excellent open source Java log system, and JBoss internal also integrated it, under JBoss by default only to the server to do a daily log, and do not have the project you deploy daily log build, but we can modify the Log4j.xml file to achieve. Log4j.xml file under server/default/conf in the JBoss installation directory, open log4j.xml file <?xml:namespace prefix = o ns = "urn: Schemas-microsoft-com:office:office "/>

This is the default configuration of log4j, let's familiarize ourselves with
<!--==============================-->
<!--Append messages to the console-->
<!--==============================-->
<!--output mode: Output to console-->
<appender name= "CONSOLE" class= "Org.apache.log4j.ConsoleAppender" >
<!--Set Channel name: Console and output mode: Org.apache.log4j.RollingFileAppender
There are 5 kinds of appender in the output mode, respectively
Org.apache.log4j.ConsoleAppender (console)
Org.apache.log4j.FileAppender (file)
Org.apache.log4j.DailyRollingFileAppender (Generate a log file every day)
Org.apache.log4j.WriterAppender (sends log information to any specified place in streaming format)-->
<param name= "Target" value= "System.out"/>
<param name= "Threshold" value= "INFO"/>
<!--threshold is a global filter that filters out information that is lower than the level you set and does not show up-->
<!--level: is the priority of the journal record, the priority from high to low divided into
Off, FATAL, ERROR, WARN, INFO, DEBUG, all.
LOG4J recommends using only the four levels of fatal, ERROR, WARN, INFO, and Debug. -->

<layout class= "Org.apache.log4j.PatternLayout" >
<!--Configure log output format-->
Parameters represent different formatting information (the parameters are listed in alphabetical order) with different parameters after the start of%:
The full name of the class to which the%c output belongs can be modified to%d{num}, and the Num class name output is surrounded as: "Org.apache.elathen.ClassName",
%C{2} will output elathen. ClassName

%d output log time in the format of%d{yyyy-mm-dd hh:mm:ss,sss}, you can specify a format such as%d{hh:mm:ss}
%l output Log event occurrence location, including class name, occurrence thread, number of lines in code
%n line break
%m output code to specify information, such as info ("message"), output message
%p output priority, that is, FATAL, ERROR, etc.
%r output the number of milliseconds it takes to display the log information from boot to
%t output The name of the thread that generated the log event
<!--the default pattern:date Priority [Category] message/n-->
<param name= "Conversionpattern" value= "%d{absolute}%-5p [%c{1}]%m%n"/>
</layout>
</appender>

<! output is: A daily log file >
<!--A time/date based rolling Appender-->
<appender name= "FILE" class= "Org.jboss.logging.appender.DailyRollingFileAppender" >
<!--set the channel name is: file, output mode dailyrollingfileappender-->
<param name= "File" value= "${jboss.server.home.dir}/log/server.log"/>
<!--log file path and file name-->
<param name= "Append" value= "false"/>
<!--set whether to add a new log on the basis of the original log when the service is restarted-->

<!--rollover at midnight-->
<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>


The above is JBoss under the log4j default configuration, the JBoss server for logging, and then we add a Web project log, in the Log4j.xml
You can add the following configuration information to the file.

  <!--A size based file rolling appender-->
  <appender name= " Com.szypt.all "class=" Org.jboss.logging.appender.RollingFileAppender "
    <param name=" File "value=" ${jboss.server.home.dir}/log/elathen.log "/>
    <param name=" Append "value=" True "/>
    <param name=" maxfilesize "value=" 500KB "/>
    <param Name= "Maxbackupindex" value= "1"/>

    <layout class= "Org.apache.log4j.PatternLayout"
      <param name= "Conversionpattern" value= "%d%-5p [%c]%m%n"/>
     </layout>    
  </appender>

  <logger name= Com.szypt ">
    <level value=" DEBUG "/>
    <appender-ref ref=" Com.szypt.all "/>
  </logger>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.