0

I have a class generating error output that I'd like to output using Logger. I'm a bit perplexed at how I do this. I have something like this:

public static void main(String[] args) throws Exception {
    ClassA foo = new ClassA();
    Logger logger = Logger.getLogger(ClassA.class.getName());
    FileHandler logFile = new FileHandler("LogToFile2.txt");
    logFile.setFormatter(new SimpleFormatter());
    logger.addHandler(logFile);
    logger.info("A message logged to the file");
    foo.bar();
}

It outputs "A message logged to the file", but the rest of the INFO stderr I receive from bar() is not captured.

Dominic Bou-Samra
  • 14,799
  • 26
  • 100
  • 156

1 Answers1

1

I assume bar hass Logger.getLogger calls in it. You should set up the logging application wide in a file called logging.properties.

Right now you are doing it on the Logger instance you retrieved for CobolProgramService.

So when you're calling Logger.getLogger in foo.bar() it will have a standard setup instead.

Check out http://www.crazysquirrel.com/computing/java/logging.jspx for some more advanced information on the topic.

jontro
  • 10,241
  • 6
  • 46
  • 71