Tomcat Log Java.util.logging.Logger use (ii)

Source: Internet
Author: User
Tags documentation tomcat server java se
# Default file output is in user ' s home directory.  
Java.util.logging.FileHandler.pattern =%h/java%u.log  
java.util.logging.FileHandler.limit = 50000  
Java.util.logging.FileHandler.count = 1  
java.util.logging.FileHandler.formatter = Java.util.logging.XMLFormatter  
  
# Limit The message that are printed on the console to INFO and above.  
Java.util.logging.ConsoleHandler.level = WARNING   
Java.util.logging.ConsoleHandler.formatter = Java.util.logging.SimpleFormatter  

1: Rewrite the output of the log format

You need to configure the Java.util.logging.ConsoleHanlder.formatter property.

This problem is not problematic in the Java SE program. Java programs can use this configuration to find custom formatter

But put it in a Web project like Tomcat. The problem comes up.

And look at the source code of Consolehandler

public class Consolehandler extends Streamhandler {
    //Private method to configure a consolehandler from Logmanager
  //properties and/or default values as specified in the class
    /Javadoc.
    private void Configure () {
        Logmanager manager = Logmanager.getlogmanager ();
	String cname = GetClass (). GetName ();

	Setlevel (Manager.getlevelproperty (CNAME + ". Level", Level.info));
	SetFilter (Manager.getfilterproperty (CNAME + ". Filter", null));
	Setformatter (Manager.getformatterproperty (CNAME + ". Formatter", New Simpleformatter ());
	try {
	    setencoding (manager.getstringproperty (CNAME + ". Encoding", null));
	\ catch (Exception ex) {
	    try { C13/>setencoding (null);
	    } catch (Exception ex2) {
		//doing a setencoding with null should always.
		Assert false;}}}
    
One line of code: This is used to set the top of the configuration file. Formatter
Setformatter (Manager.getformatterproperty (CNAME + ". Formatter", New Simpleformatter ());
Tracking in to find: Classloader.getsystemclassloader can not reflect to the specified class

  Formatter Getformatterproperty (string name, Formatter defaultvalue) {
	string val = GetProperty (name);
	try {
	    if (val!= null) {
		Class clz = Classloader.getsystemclassloader (). LoadClass (val);
	        Return (Formatter) clz.newinstance ();
	    }
	catch (Exception ex) {
	    //We got one of a variety of exceptions in creating the
	    //class or creating an instance.< c10/>//Drop through.
	}

Continue to check out the Tomcat related documentation

Http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html

System-this class loader is normally initialized from the contents of the CLASSPATH environment. All such classes are visible to both Tomcat internal classes, and to Web applications. However, the standard Tomcat startup scripts ($CATALINA _home/bin/catalina.sh or%catalina_home%\bin\catalina.bat) Totally ignore the contents of the CLASSPATH environment variable, and itself build the System class instead from T He following repositories: $CATALINA _home/bin/bootstrap.jar-contains, the main () method, which used to initialize the


Tomcat server, and the class loader implementation classes it depends on. $CATALINA _base/bin/tomcat-juli.jar or $CATALINA _home/bin/tomcat-juli.jar-logging implementation classes. These include the enhancement classes to java.util.logging API, known as Tomcat Juli, and a package-renamed copy of Apache Com Mons Logging Library used internally by Tomcat.


Logging documentation for more details. If Tomcat-juli.jar is present in $CATALINA _base/Bin, it is used instead to the one in $CATALINA _home/bin. It is useful in certain logging configurations $CATALINA _home/bin/commons-daemon.jar-the classes from Apache Commons D Aemon project. This JAR file isn't present in the CLASSPATH built by Catalina.bat|. SH scripts, but is referenced from the manifest file of Bootstrap.jar.

found that Systemclassloader can only load three jars under the Tomcat-7.0.34\bin directory.

That is to say, if you need to continue using the JDK's own log, you can't rewrite formater ...


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.