Java Logging Errors

I'm using java.util.logging (I don't want to use jakarta commons logging in the case). I have my logged messages going to both the console and a file and it is working OK. Now I want the error messages that show up in the console (for example when I get a NullPointerException) to also show up in the file. How can I do that?

Who is Participating?
petmagdyConnect With a Mentor Commented:
take a look at this sample:
CodingExpertsConnect With a Mentor Commented:
import java.util.logging.*;

public class Nose {
    private static Logger logger = Logger.getLogger("com.wombat.nose");
    private static FileHandler fh = new FileHandler("mylog.txt");
    public static void main(String argv[]) {
        // Send logger output to our FileHandler.
        // Request that every detail gets logged.
        // Log a simple INFO message."doing stuff");
        try {
        } catch (Error ex) {
            logger.log(Level.WARNING, "trouble sneezing", ex);
adgAuthor Commented:
That didn't work! I changed both the logger and handler level to ALL. The exception details show up in the console but not in my file. I do get all the messages that I log in my file but not the ones that the system is logging. I thought it might be a filtering issue but the default filter is supposed to pass all messages.  Since this  may be more complicated than I thought I'll increase the points if I get the answer I'm looking for.  Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.