如何在eclipse上禁用控制台LOG

时间:2015-01-14 15:35:24

标签: java hibernate


我在不同的地方读了很多关于这个话题的内容,但这很令人困惑。 我主要使用两个框架,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。 谢谢!

1 个答案:

答案 0 :(得分:1)

如果要禁用或减少hibernate日志,请在项目中添加以下依赖项(Maven工件表示法&lt; groupId&gt;:&lt; artifactId&gt;:&lt; version&gt;):

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

版本也可以更新。

然后添加一个名为&#34; log4j.properties&#34;的资源文件。到您的项目,以便它稍后出现在打包的jar文件的根文件夹中。从以下log4j配置开始关闭&#34; org.hibernate&#34;记录消息:

# 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
# ...

根据需要选择根记录器的日志级别,并为&#34; org.asteriskjava&#34;定义另一个日志追加器。