Title: Java-Logging-Lesson 2-Logging using the ConsoleHandler and the FileHandler
Duration: 16 minutes
Summary: In this video, we continue our discussion of logging in java. In the first example, we show how to log to the console. To do that, we use the ConsoleHandler class. We tie the handler to the logging class by using the Logger’s addHandler method. Then we simply log the messages as we did in the previous video. However, we noticed that the messages are logged twice because the logger sends the log record to its handlers and to all the handlers of the ancestor loggers. To avoid that, we use setUseParentHandlers method and pass it the boolean false. Finally, we showed how to log to a file using the FileHandler. We specified the file name and a boolean property to append the messages to the file instead of writing over the current messages.
Methodology of the development of example: Good coding standard and simplified design to illustrate the key points.
Technology Used: Java - Logging
Keywords: java.util.logging, Logger, getLogger, severe, warning, info, LogRecord, Level, log, logp, ConsoleHandler, addhandler, setUseParentHandlers, FileHandler.