如何在 Eclipse 上禁用控制台日志

How do I disable the console LOG on eclipse


我在不同的地方读过很多关于这个话题的文章,但它非常令人困惑。 我主要使用两个框架,hibernate 和 java-asterisk。 我在控制台上的内容如下:


INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Jan 14, 2015 3:25:04 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jan 14, 2015 3:25:04 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/gomobile]
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Jan 14, 2015 3:25:04 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jan 14, 2015 3:25:04 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Jan 14, 2015 3:25:04 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/gomobile]
Jan 14, 2015 3:25:04 PM org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
Jan 14, 2015 3:25:04 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Jan 14, 2015 3:25:04 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
Jan 14, 2015 3:25:04 PM org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/gomobile]
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
Jan 14, 2015 3:25:04 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
Jan 14, 2015 3:25:04 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Jan 14, 2015 3:25:04 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Jan 14, 2015 3:25:04 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/gomobile]
Jan 14, 2015 3:25:04 PM org.asteriskjava.manager.internal.ManagerConnectionImpl connect
INFO: Connecting to localhost:5038
Jan 14, 2015 3:25:04 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
INFO: Connected via Asterisk Call Manager/2.5.0
Jan 14, 2015 3:25:04 PM org.asteriskjava.manager.internal.ManagerConnectionImpl setProtocolIdentifier
WARNING: Unsupported protocol version 'Asterisk Call Manager/2.5.0'. Use at your own risk.
Jan 14, 2015 3:25:04 PM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Successfully logged in
Jan 14, 2015 3:25:04 PM org.asteriskjava.manager.internal.EventBuilderImpl buildEvent
INFO: No event class registered for event type 'fullybooted', attributes: {status=Fully Booted, event=FullyBooted, privilege=system,all}. Please report at http://jira.reucon.org/browse/AJ
Jan 14, 2015 3:25:06 PM org.asteriskjava.manager.internal.ManagerConnectionImpl doLogin
INFO: Determined Asterisk version: Asterisk 1.6
Jan 14, 2015 3:25:06 PM org.asteriskjava.manager.internal.ManagerConnectionImpl disconnect
INFO: Closing socket.
Jan 14, 2015 3:25:06 PM org.asteriskjava.manager.internal.ManagerReaderImpl run
INFO: Terminating reader thread: No more lines available: null

这是我的依赖项:

antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.7.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-logging-3.1.3.GA.jar

我是 运行 xUBUNTU 14.04 上的 eclipse luna。 谢谢!

如果您想禁用或减少休眠日志,请将以下依赖项(Maven 工件表示法 ::)添加到您的项目中:

  • org.slf4j:slf4j-log4j12:1.6.6
  • log4j:log4j:1.2.14

版本也可以更新。

然后将名称为 "log4j.properties" 的资源文件添加到您的项目中,以便它稍后出现在打包的 jar 文件的根文件夹中。从以下 log4j 配置开始以关闭 "org.hibernate" 日志消息:

# Root logger
log4j.rootLogger=INFO

# Log appender for package stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%p] %c.%M(%F:%L) - %m%n

# Log appender for org.hibernate
log4j.logger.org.hibernate=OFF,hibernate
log4j.appender.hibernate.Encoding=UTF-8
log4j.appender.hibernate.layout.ConversionPattern=%d [%p] %c.%M(%F:%L) - %m%n
log4j.appender.hibernate.layout=org.apache.log4j.PatternLayout
log4j.appender.hibernate=org.apache.log4j.ConsoleAppender

# Further log appenders
# ...

根据需要为根记录器选择日志级别,并为 "org.asteriskjava" 定义另一个日志附加程序。