Java util logging.properties: How to connect to two different files

I place logging.properties in the WEB-INF / classes tomcat directory

I would like to register in two different files. For example: org.pkg1 goes to one file, and org.pkg2 goes to a separate file.

I can configure one file, but not two. Is it possible?

+4
source share
5 answers

I finally figured it out. In tomcat, they extend the java util ("JULI") protocols to enable this feature. Here is the logging.properties file that I entered in the WEB-INF directory, which finally completed what happened after ......:

handlers=1console.java.util.logging.ConsoleHandler, 2jsp.org.apache.juli.FileHandler, 3financials.org.apache.juli.FileHandler
.handlers=1a.java.util.logging.ConsoleHandler

jsp.level=ALL
jsp.handlers=2jsp.org.apache.juli.FileHandler
org.apache.jasper.level = FINE
org.apache.jasper.handlers=2jsp.org.apache.juli.FileHandler
org.apache.jsp.level = FINE
org.apache.jsp.handlers=2jsp.org.apache.juli.FileHandler

com.paypal.level=ALL
com.paypal.handlers=3financials.org.apache.juli.FileHandler

3financials.org.apache.juli.FileHandler.level=ALL
3financials.org.apache.juli.FileHandler.directory=${catalina.base}/logs
3financials.org.apache.juli.FileHandler.prefix=financials.

2jsp.org.apache.juli.FileHandler.level=ALL
2jsp.org.apache.juli.FileHandler.directory=${catalina.base}/logs
2jsp.org.apache.juli.FileHandler.prefix=jsp.

1console.java.util.logging.ConsoleHandler.level=FINE
1console.java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+9
source

logging.properties, . , .

public class CustomAFileHandler extends FileHandler {
   public DebugFileHandler() throws IOException, SecurityException {
      super();
   }
}

public class CustomBFileHandler extends FileHandler {
   public DebugFileHandler() throws IOException, SecurityException {
      super();
   }
}

logging.properties

...
handlers=<pkg_name>.CustomAFileHandler, <pkg_name>.CustomBFileHandler, java.util.logging.ConsoleHandler

<pkg_name>.CustomAFileHandler.level=ALL
<pkg_name>.CustomAFileHandler.pattern=%h/A%u.log
<pkg_name>.CustomAFileHandler.limit=50000
<pkg_name>.CustomAFileHandler.count=1 
<pkg_name>.CustomAFileHandler.formatter=java.util.logging.SimpleFormatter


<pkg_name>.CustomBFileHandler.level=ALL
<pkg_name>.CustomBFileHandler.pattern=%h/B%u.log
<pkg_name>.CustomBFileHandler.limit=50000
<pkg_name>.CustomBFileHandler.count=1 
<pkg_name>.CustomBFileHandler.formatter=java.util.logging.SimpleFormatter
...
+4

java.util.logging, . , - FileHandler logging.properties, , , :

org.pkg1.handlers=java.util.logging.FileHandler
org.pkg2.handlers=org.pkg2.FileHandler
java.util.logging.FileHandler.pattern="org_pkg1_%u.%g.log"
org.pkg2.FileHandler.pattern="org_pkg2_%u.%g.log"

/PKG2/FileHandler.java:

package org.pkg2;

import java.util.logging.*;

public class FileHandler extends java.util.logging.FileHandler {
    public FileHandler() {
        super(LogManager.getLogManager().getProperty("org.pkg2.FileHandler.pattern"));
    }
}
+1

jdk ( jdk 7 jdk 8).

; "java.util.logging.FileHandler".

public class JULTestingFileHandler extends FileHandler {

    public JULTestingFileHandler() throws IOException, SecurityException 
    {
        super();    
    }
}

;

com.xxx.handlers = com.xxx.JULXXXFileHandler

com.xxx.JULXXXFileHandler.pattern   = ./logs/test1_test2.%u.%g.log
0

java.util.logging , :

2.2

, . "% t" .

public static void main(String[] args) {
        Handler fh = new FileHandler("%t/wombat.log");
        Logger.getLogger("").addHandler(fh);
        Logger.getLogger("com.wombat").setLevel(Level.FINEST);
        ...
    }

, , .properties, , . LoggerManager

0

All Articles