Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java util logging.properties: How to log to two different files

I am placing a logging.properties in the WEB-INF/classes dir of tomcat

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

I can get one file configured, but not two. Is that possible?

like image 947
David Parks Avatar asked Sep 03 '10 21:09

David Parks


2 Answers

I finally figured this out. In tomcat they extend java util logging ("JULI") to enable this functionality. Here's a logging.properties file that I put in the WEB-INF directory that finally accomplished what I was 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
like image 71
David Parks Avatar answered Sep 17 '22 14:09

David Parks


Speaking of logging.properties configuration, I did not found any mechanism to use more that one appender. I made simple workaround that works for me.

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

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

And my 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
...
like image 23
Teodor Simchev Avatar answered Sep 17 '22 14:09

Teodor Simchev