Java Logging Errors

Posted on 2004-11-24
Last Modified: 2010-03-31
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?

Question by:adg
    LVL 13

    Accepted Solution

    take a look at this sample:
    LVL 6

    Assisted Solution

    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);
    LVL 3

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now