https://bz.apache.org/bugzilla/show_bug.cgi?id=58003

            Bug ID: 58003
           Summary: Official website give a wrong example
           Product: Log4j
           Version: 1.2.17
          Hardware: Macintosh
            Status: NEW
          Severity: major
          Priority: P2
         Component: Site & Docs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

The first page of website give us an example to explain how log4j works.

 import com.foo.Bar;

 // Import log4j classes.
 import org.apache.log4j.Logger;
 import org.apache.log4j.BasicConfigurator;

 public class MyApp {

   // Define a static logger variable so that it references the
   // Logger instance named "MyApp".
   static Logger logger = Logger.getLogger(MyApp.class);

   public static void main(String[] args) {

     // Set up a simple configuration that logs on the console.
     BasicConfigurator.configure();

     logger.info("Entering application.");
     Bar bar = new Bar();
     bar.doIt();
     logger.info("Exiting application.");
   }
 }

The issue is the line below:
static Logger logger = Logger.getLogger(MyApp.class);
The page said logger's name is "MyApp", if we set log4j.logger.com.foo=WARN
The debug log in Bar class would be disabled(that is right), and the info log
in MyApp class works as usual, because it is not a child of "com.foo".

But unfortunately if we use the method getLogger with the parameter MyApp.class
to get a logger, this logger's name is "com.foo.Bar.MyApp", not "MyApp".

-- 
You are receiving this mail because:
You are the assignee for the bug.
You are on the CC list for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to