JBoss Log Output settings

Source: Internet
Author: User
Tags log log jboss log4j

Article Source: http://blog.csdn.net/nuoyan666/article/details/5935772

If you do not optimize the configuration, JBoss Project error will be very troublesome, in the Jboss4.2.2ga version, by default, all debug information is lost, just run JBoss, Server.log log is almost 1 m, and then stop JBoss, what do not do, have been generated by the creation of the log, can only use a word to describe: fees.

But first of all, don't be so excited, young people, should control their own mentality, the Impulse is Warcraft. Log too much does not use, originally these log the biggest function is convenient to check the wrong, but if you generate n row of log, find what you want, I might as well check the program again. Therefore, in different applications, the configuration of your log, so that the project more smoothly to do oh.

OK, turn to the point, this article is for JBOSS4 log4j configuration, others please refer to the corresponding article.

The log4j configuration of the JBOSS4 is placed by default in the conf/directory of the Deploy directory, for example, now I put the ear into JBoss default directory, then log4j file is jboss/server/default/conf/ Jboss-log4j.xml, find it, let's analyze what's inside it.

First, the first paragraph, a file Appender, the code is the following XML code <!--A Time/date based rolling appender-<appenderName= "FILE" class= "Org.jboss.logging.appender.DailyRollingFileAppender"> <errorhandlerClass= "Org.jboss.logging.util.OnlyOnceErrorHandler"/><paramName= "File" value= "${jboss.server.log.dir}/server.log"/><paramName= "Append" value= "false"/><!--Rollover at midnight<paramName= "Datepattern" value= "'. ' Yyyy-mm-dd "/><!--Rollover at the top of each hour<paramName= "Datepattern" value= "'. ' Yyyy-mm-dd-hh "/>--><layoutClass= "Org.apache.log4j.PatternLayout"><!--the default pattern:date priority [Category] message/n--<paramName= "Conversionpattern" value= "%d%-5p [%c]%m%n"/><!--the full pattern:date MS priority [Category] (THREAD:NDC) message/n<paramName= "Conversionpattern" value= "%d%-5r%-5p [%c] (%t:%x)%m%n"/>--></layout></appender>[XML] View Plain copy print? <!-- A time/date based rolling appender -->       <appender name= "FILE"  class= "Org.jboss.logging.appender.DailyRollingFileAppender" >         <errorhandler class= "Org.jboss.logging.util.OnlyOnceErrorHandler"/ >         <param name= "File"  value= "${ Jboss.server.log.dir}/server.log "/>         <param name=" Append " value=" false "/>            <!--  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>  

<!--A Time/date based rolling appender-to <appender name= "FILE" class= "Org.jboss.logging.appender.DailyRolli Ngfileappender "> <errorhandler class=" Org.jboss.logging.util.OnlyOnceErrorHandler "/> <param name=" File "value=" ${jboss.server.log.dir}/server.log "/> <param name=" Append "value=" false "/> <!--Roll Over 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= "Conve
     Rsionpattern "value="%d%-5r%-5p [%c] (%t:%x)%m%n "/>- </layout> </appender>
 

The above section is the basic configuration of the JBoss default output to the Log/server.log file, its name is file, it is set by itself, it will be referenced in other places with this reference name, and then the type of Appender is Dailyrollingfileappender, meaning is to generate a new Server.log file every day, at this time someone will ask, how every day is Server.log, then yesterday's not cover off. Don't worry, this kind of thing the developer already thought, it will have some parameters to set it, automatically let you the day before the log to change the other name, of course, there are several types of appender, this article is the reference, according to the needs of your project to set it.

The first parameter in the middle is the output address of the log file, as you can see, change it.

The second parameter <param name= "Append" value= "false"/>, meaning that you should not overwrite the previous log when running JBoss, which is useful when developing debugging, when you set it to false, Every time you re-run JBoss, the newly generated log is covered by the old, so it is easier to find, and do not have to remove it yourself, but if it is formally used, it can be set to true according to the need, so that all the logs will be saved, at intervals, You can find the log information at any time before.

There are some parameter settings file for the previous day's log file name, you can notice that there is a datepatternin the middle of the configuration, this is to set your log will be changed to what name, it is at midnight every night, very automatic bar, you look at the back of it '.' Yyyy-mm-dd, you will know what the file name of log will be replaced the day before. Spoon is not carried out here. It can also be a bit more ruthless, generate a log per hour how, you want to do, learn to match it.

Further down, there is a patternlayout, this is the output text style, this is the text, but it also has a change oh, can be converted to Web page form of the log (looks like a bit), there are several other, we have time to play, But this patternlayout is the most commonly used, but also the most professional, want to become a professional, just use it. Hehe, joking, the other several are also very professional, even more professional.

Just contact log4j People will not understand the role of patternlayout, but you have used, you know how tough it is, the form of log display with your mind to change, you can output a lot of information, such as class name, class line number, detail time, log body, and log level, etc. If you develop a log tool yourself, will you be so strong. I used to do one, can only hard code, and nothing else can do, use it, will be angry half your death. I am angry one-third, because I write, hehe, biological, can not blame it all, that blame who ...

Then there is a conversionpattern parameter, it is the configuration log display format, its detailed format used in the post will be posted, there is a need to go to see, but with it the default is very good.

Well, before the introduction of a default file Appender, there is a console of the Appender, do not introduce it, is displayed in the JBoss console log style, here we will not talk about.

Xu The two default, you can also customize the Appender Oh, such as your project has different types of log output to a different log log, or you do not want to change the default log configuration, but also to find a clever, anyway is very personalized, to generate a number of different log is OK.

Here I copied a file of the Appender, and then made a small change, I can generate my custom log, the code is as follows XML code <!--A Time/date based rolling appender-<appenderName= "Myappender" class= "Org.jboss.logging.appender.DailyRollingFileAppender"><errorhandlerClass= "Org.jboss.logging.util.OnlyOnceErrorHandler"/><paramName= "File" value= "${jboss.server.log.dir}/mylog.log"/><paramName= "Append" value= "false"/><!--Rollover at midnight<paramName= "Datepattern" value= "'. ' Yyyy-mm-dd "/><!--Rollover at the top of each hour<paramName= "Datepattern" value= "'. ' Yyyy-mm-dd-hh "/>--><layoutClass= "Org.apache.log4j.PatternLayout"><!--the default pattern:date priority [Category] message/n-<!--<param name= "Conversionpattern" V Alue= "%d%-5p [%c]%m%n"/>--> <!--the full pattern:date MS priority [Category] (THREAD:NDC) message/ N--><paramName= "Conversionpattern" value= "%d%-5r%-5p [%c] (%t:%x)%m%n"/></layout></appender> [XML]View Plain copy print? <!--A Time/date based rolling appender-to <appender name= "Myappender" class= "Org.jboss.logging.appender.Dail Yrollingfileappender "> <errorhandler class=" org.jboss.logging.util.OnlyOnceErrorHandler "/> <param na Me= "File" value= "${jboss.server.log.dir}/mylog.log"/> <

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.