Obtaining a Logger object:
Logger is a class of org.apache.log4j package and its object is used to insert logging statements in a java class.
To obtain a Logger object we call a static factory method of the class getLogger () method.
Logger objects are created on “per class basis”. It means one Logger object is generated for one class to insert log statements.

Syntax: 
Logger logger=Logger.getLogger (String classname);
Logger logger=Logger.getLogger (Class clazz);
Example:
Logger logger=Logger.getLogger (“SampleLogger”);
Logger logger=Logger.getLogger (SampleLogger.class);

Note:- In a class, we create more than one Logger object then they became reference to one object only but not different objects.
For example:
Logger logger1=Logger.getLogger (SampleLogger.class);
Logger logger2=Logger.getLogger (SampleLogger.class);

Here, logger1 and logger2 are reference pointing to a Single Logger object.
If you want to know just compare logger1 and logger2 objects by using == (equal) operator.

1 comments:

  1. Nice info..Better you could have given in detail how to configure the jars with the simple program..

    ReplyDelete