You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2015/06/04 16:58:53 UTC
[Bug 58003] New: Official website give a wrong example
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: log4j-dev@logging.apache.org
Reporter: bfeng@thoughtworks.com
CC: log4j-dev@logging.apache.org
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[Bug 58003] Official website give a wrong example
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58003
--- Comment #2 from Gary Gregory <ga...@gmail.com> ---
Also note that you should use Log4j 2 if possible since it is the version being
actively developed and maintained, not 1.2.
--
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[Bug 58003] Official website give a wrong example
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58003
bfeng@thoughtworks.com changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
Severity|major |critical
--
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[Bug 58003] Official website give a wrong example
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58003
--- Comment #1 from Gary Gregory <ga...@gmail.com> ---
This example does not define a package for its class MyApp, IOW there is no
package statement.
Loggger.getLogger(Class) simply calls: LogManager.getLogger(clazz.getName())
So the only way you are getting "com.foo.Bar.MyApp" from this call is if you
have defined the MyApp class in a "com.foo.Bar" package, which the example does
not do.
--
You are receiving this mail because:
You are on the CC list for the bug.
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[Bug 58003] Official website give a wrong example
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=58003
bfeng@thoughtworks.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |WORKSFORME
Status|NEW |RESOLVED
--
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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org