You have to use Logger.getLogger() method. The process of creating a new Logger in Java is quite simple. Well, I will discuss the Loggers in the latter part of this article, but before that, let me show you how to create a Logger in Java. Also, all the Logger names must be based on the class or the package name of the logged component.Īpart from this, each Logger keeps a track of the nearest existing ancestor in the Logger namespace and also has a “Level” associated with it. They are normally named using the hierarchical dot-separated namespace. You can use multiple loggers in a single class to respond to various events or use Loggers in a hierarchy. Loggers in Java are objects which trigger log events, They are created and are called in the code of the application, where they generate Log Events before passing them to the next component which is an Appender. Now, let us understand what is a logger in Java in depth. Apart from this, you can also use more than one Filters to specify which Appenders should be used for events. Then it formated the record using the Layout according to the required format. When an application makes a logging call, the Logger component records the event in a LogRecord and forwards it to the appropriate Appender. You can refer to the below image for the working of all the three components:
0 Comments
Leave a Reply. |