Separating log messages by level

J

James

Hello all,
Is there a way to have java.util.logging send LogRecords to different
handlers based on their level?

What I'm aiming for is a log file for "everything", and a separate
file just for errors and above.

Thanks!
James
 
J

James

What I'm aiming for is a log file for "everything", and a separate
Yeah, put TWO FileHandlers in your Logger, set the Levels different, so
one logs everything and one logs just errors and up.

See the "addHandler()" method (I think that's the name.)

Ah, I should have said - I'm configuring logging from a properties
file, and although I can add two FileHandlers:
handlers= java.util.logging.FileHandler, java.util.logging.FileHandler

I don't see a way to configure those two Handlers differently. Am I
missing something?
 
A

Arne Vajhøj

James said:
Ah, I should have said - I'm configuring logging from a properties
file, and although I can add two FileHandlers:
handlers= java.util.logging.FileHandler, java.util.logging.FileHandler

I don't see a way to configure those two Handlers differently. Am I
missing something?

If you want to do advanced logging, then us elog4j instead
of java.util.logging !

:)

One possible workaround is:

package february;

import java.io.IOException;
import java.util.logging.FileHandler;

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

package february;

import java.io.IOException;
import java.util.logging.FileHandler;

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

february.MultiLog.level = FINE
handlers = february.FileHandlerA,february.FileHandlerB
february.FileHandlerA.level = FINE
february.FileHandlerA.formatter = java.util.logging.SimpleFormatter
february.FileHandlerA.pattern = C:/log1.log
february.FileHandlerB.level = SEVERE
february.FileHandlerB.formatter = java.util.logging.SimpleFormatter
february.FileHandlerB.pattern = C:/log2.log

Not particular elegant, but it works.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top