By configuring log4j. xml under JBoss to implement web application log author blog: http://blog.csdn.net/elathen/
Log4j is an excellent open-source Java log system, and JBoss also integrates it. By default, it only performs daily logs on the server under JBoss, no daily log building is performed for the project you deploy, but we can modify log4j. XML file. Open the log4j. xml file in the server/default/conf directory under the JBoss installation directory.
This is the default log4j configuration.
<! -- =================================== -->
<! -- Append messages to the console -->
<! -- =================================== -->
<! -- Output mode: output to the console -->
<Appender name = "console" class = "org. Apache. log4j. leleappender">
<! -- Set the channel name: console and output mode: org. Apache. log4j. rollingfileappender
There are 5 appender output methods:
Org. Apache. log4j. leleappender (console)
Org. Apache. log4j. fileappender (file)
Org. Apache. log4j. dailyrollingfileappender (a log file is generated every day)
Org. Apache. log4j. writerappender (send log information to any specified place in stream format) -->
<Param name = "target" value = "system. Out"/>
<Param name = "threshold" value = "info"/>
<! -- Threshold is a global filter that does not display information lower than the configured level. -->
<! -- Level: indicates the priority of a diary record. The priority ranges from high to low.
Off, fatal, error, warn, info, debug, all.
Log4j only supports four levels: fatal, error, warn, info, and debug. -->
<Layout class = "org. Apache. log4j. patternlayout">
<! -- Configure the log output format -->
Parameters start with %. Different parameters indicate different formatting information (the parameters are listed alphabetically ):
% C indicates the full name of the output class, which can be changed to % d {num}. The output of the num class name is as follows: "org. Apache. elathen. classname ",
% C {2} Will output elattings. classname
% D: the log output time is in the format of % d {yyyy-mm-dd hh: mm: SS, SSS}. You can specify the format, for example, % d {hh: mm: SS}
% L location of log event output, including category name, thread, number of lines in the code
% N line break
% M output code specified information, such as Info ("message"), Output Message
% P output priority, namely, fatal, error, etc.
% R the number of milliseconds it takes to output the log information from startup to display.
% T name of the thread that outputs the log event
<! -- The default pattern: date priority [category] Message/n -->
<Param name = "conversionpattern" value = "% d {absolute} %-5 p [% c {1}] % m % N"/>
</Layout>
</Appender>
<! Output Method: One log file per day>
<! -- A time/date based Rolling appender -->
<Appender name = "file">
<! -- Set the channel name to file. The output method is dailyrollingfileappender -->
<Param name = "file"/>
<! -- Log file path and file name -->
<Param name = "APPEND" value = "false"/>
<! -- Set whether to add a new log to the base of the original log when the service is restarted -->
<! -- Rolover at midnight each day -->
<Param name = "datepattern" value = "'. 'yyyy-mm-dd"/>
<! -- Rolover 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 %-5 p [% C] % m % N"/>
<! -- The full pattern: Date MS priority [category] (thread: NDC) Message/n
<Param name = "conversionpattern" value = "% d %-5R %-5 p [% C] (% T: % x) % m % N"/>
-->
</Layout>
</Appender>
The above is the default configuration of log4j in JBoss, which is used to record the logs of JBoss server. Next we will add the logs of WEB projects in log4j. xml
Add the following configuration information to the file.
<! -- A Size Based File rolling appender -->
<Appender name = "com. szypt. All">
<Param name = "file"/>
<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 %-5 p [% C] % m % N"/>
</Layout>
</Appender>
<Logger name = "com. szypt">
<Level value = "debug"/>
<Appender-ref = "com. szypt. All"/>
</Logger>