JBOSS4 Project log log to other files

Source: Internet
Author: User
Tags log log jboss log4j

If not optimized configuration, JBoss Project error will be very troublesome, in the JBOSS4.2.2GA version, the default will all of the debug information lost all over, just run JBoss, Server.log's log is almost 1 m, and then stop JBoss, what is not done, have been generated by the creation of the log, can only use a word to describe: fee objects.

But don't say so exciting, young people, should control their own mentality, Impulse is Warcraft. Log too much do not use, the original log is the biggest function is easy to check the wrong, but if you generate n row log, find out what you want, I might as well check the program. Therefore, in different application situations, configure your log, to make the project more smoothly.

OK, turn to the point, this article is for the JBOSS4 log4j configuration, others see the appropriate article.

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

  First is the first paragraph, a file Appender, the code is as follows XML code    <!-- 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>  

The above section is the basic configuration of JBoss default output to the Log/server.log file, its name is file, this is set by itself, in other places will use this cited name to refer to it, and then Appender type is Dailyrollingfileappender, meaning that every day to generate a new Server.log file, 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 developers have long thought, it will have some parameters to set it, automatically let you the day before the log to change other names, of course, there are several types of appender, this article is the most behind the reference, according to your project needs to set it.

The middle of the first parameter is the log file output address, we understand that, the change on the line.

The second parameter <param name= "Append" value= "false"/>, meaning that when you run JBoss, do not overwrite the previous log, which is useful when developing debugging, and you set it to False Every time you rerun JBoss, the newly generated log is covered by the old one, so it's easier to find, and you don't have to delete it yourself, but if it's officially used, you can set it to true as needed, so that all the logs are saved, and for a while, You'll be able to find log information at any time before.

The above mentioned that 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 previous log will be changed to what name, it at midnight every night, very automatic bar, you see it behind the '.' Yyyy-mm-dd, you will know the name of the log of the day before will be replaced by what. There is no cram here. It can also show a bit more malicious, every hour to generate a log how do 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, you can replace the Web page form of the log (looks will be cool), 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, use it. Oh, joking, the other several are also very professional, and even more professional.

People who have just come in contact with LOG4J will not understand the role of patternlayout, but after you use, you know how strong it is, the form of log display changes with your mind, you can output a lot of information, such as class name, class line number, detailed time, log body, as well as log level, If you develop a log tool yourself, will you be so strong? I have done one before, can only hard code, nothing else can do, use it, will kill you half. I am angry one-third, because I write well, hehe, biological, can't blame it, that blame who ...

Then there is a conversionpattern parameter, it is configured log display format, its detailed format used at the end of this article will be posted, need to go to see, but with its default is very good.

OK, previously introduced a default file Appender, there is a console of the Appender, not to introduce the bar, is displayed in the JBoss console log style, we will not talk about.

Xu These two default, can also customize Appender Oh, such as your project has different types of log output to different log log, or you do not want to change the default log configuration, another find clever, anyway is very personalized, how many different log can be generated.

  Here I copied a file of Appender, and then made a small change, I can generate my own custom log, the code is as follows XML code    <!-- a time/date based  rolling appender -->   <appender name= "Myappender"  class= " Org.jboss.logging.appender.DailyRollingFileAppender ">      <errorHandler  class= "Org.jboss.logging.util.OnlyOnceErrorHandler"/>      <param name= " File " value=" ${jboss.server.log.dir}/mylog.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>  

It will generate a MyLog.log file in the log directory, but it is important to note that it will not do anything until there is no other code referencing the Appender.

In the Jboss-log4j.xml file, there are many of the following code XML code <!--Limit the Org.jboss category to INFO as its DEBUG is verbose--> <category name= "Org.jboss" > <priority value= "INFO"/> </category>

What's it for? It is one of the log4j of the powerful, It detects information that is Org.jboss output, to limit debug information output, previously said JBoss log information is very large, because it defaults to all the debug information out, these JBoss debug information for us, the civilian population, you add me above this section, all the J BOSS Debug information will not output, try it, the other category how you change. Tell me about one of my experiences, you run JBoss, then stop it, open the server.log, and you'll see a lot of log information, like the following

2008-10-18 16:00:59,203 debug[org.apache.resource.deployment.RARDeployment] Required license Terms exist, View Meta-inf/ra.xml in .../deploy/jboss-ha-local-jdbc.rar

Look at the bold part above, it is by class Org.apache.resource.deployment.RARDeplo

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.