1

log4j.properties

log4j.rootLogger=FINE, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c:%L - %m%n

log4j.category.my.root.package=FINEST

My Class

public class MyClass {
    private static final Logger logger = Logger.getLogger(MyClass.class.getName());


    public boolean download(String destinationPath) {
        HttpURLConnection con = null;
        int i;

        try {
            logger.log(Level.FINE, "Download URL {0}", new Object[] { url.toString()});
        con = (HttpURLConnection) url.openConnection();
        con.setInstanceFollowRedirects(true);

        InputStream is = con.getInputStream();
....

Despite my breakpoint reaching the url.openConnection(); line, the Level.FINE doesn't show up in my console. Here's the console I do see:

INFO: Order: #298596(Status: 1)
15:00:58,532 DEBUG main org.hibernate.engine.transaction.spi.AbstractTransactionImpl:158 - begin
15:00:58,532 DEBUG main org.hibernate.engine.jdbc.internal.LogicalConnectionImpl:295 - Obtaining JDBC connection
15:00:58,558 DEBUG main org.hibernate.engine.jdbc.internal.LogicalConnectionImpl:301 - Obtained JDBC connection
15:00:58,559 DEBUG main org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction:69 - initial autocommit status: true
15:00:58,559 DEBUG main org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction:71 - disabling autocommit
15:00:58,615 DEBUG main org.hibernate.SQL:104 - MY-QUERY
15:00:58,657 DEBUG main org.hibernate.engine.transaction.spi.AbstractTransactionImpl:173 - committing
15:00:58,661 DEBUG main org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction:113 - committed JDBC Connection
15:00:58,661 DEBUG main org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction:126 - re-enabling autocommit
15:00:58,664 DEBUG main org.hibernate.engine.jdbc.internal.LogicalConnectionImpl:314 - Releasing JDBC connection
15:00:58,664 DEBUG main org.hibernate.engine.jdbc.internal.LogicalConnectionImpl:332 - Released JDBC connection
15:00:58,664 DEBUG main org.hibernate.engine.jdbc.internal.proxy.ConnectionProxyHandler:219 - HHH000163: Logical connection releasing its physical connection
INFO: #298596: Importing...

How come I'm not seeing my own custom logging?

Changing log4j.rootLogger=FINE, stdout to log4j.rootLogger=INFO, stdout does hide all DEBUG from the console, so I know this file is being parsed.

4

2 回答 2

2

代替

log4j.rootLogger=FINE, stdout

log4j.rootLogger=TRACE, stdout

并在这里查看:http: //logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.htmlhttp://logging.apache.org/log4j/1.2/manual.html

第二个链接说:

Loggers may be assigned levels. The set of possible levels, that is:

TRACE,
DEBUG,
INFO,
WARN,
ERROR and
FATAL
于 2013-06-27T19:08:53.847 回答
1

log4j 的级别与 Java Loggin Framework 不同。

对于 log4j,所有可能的选项是:

  • ALL
  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF
于 2013-06-27T19:11:13.457 回答