Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use JBoss logging brought by Hibernate?

I am writing standalone java application which is using Hibernate. Maven brought jboss-logging library for me. I am not using JBoss. The question is: can I log with this library only, or I need to download some logging implementation like log4j?

like image 308
Suzan Cioc Avatar asked Sep 17 '12 09:09

Suzan Cioc


People also ask

What does JBoss use for logging?

Logging is controlled from a central conf/jboss-log4j. xml file. This file defines a set of appenders specifying the log files, what categories of messages should go there, the message format and the level of filtering. By default, JBoss produces output to both the console and a log file ( log/server.

What logger does Hibernate use?

Since version 4.0, Hibernate uses the JBoss Logging library to write messages to a log file. This library is a logging bridge that integrates different log frameworks. You can decide which of the following frameworks you want to use for your application: JBoss LogManager.


3 Answers

JBoss Logging is just a logging facade. To configure your loggers, e.g. use/add handlers, you need a log manager like JBoss Log Manager, the J.U.L. log manager, logback or log4j.

JBoss Logging will attempt to discover which log manager is being used. You can specify which log manager you'd like to use with the org.jboss.logging.provider system property. The allowed values for `org.jboss.logging.provider' are:

  • jboss - for JBoss Log Manager
  • jdk - For the J.U.L. log manager
  • log4j - For the log4j log manager
  • slf4j - For logback with slf4j

Hibernate uses JBoss Logging for it's i18n capabilities, it's vararg logging methods and the ability to not be tied to a log manager.

Of course you can absolutely use JBoss Logging in your project. If you want to configure logging handlers you'd also have to use a log manager as well.

like image 57
James R. Perkins Avatar answered Oct 19 '22 23:10

James R. Perkins


afaik, jboss-logging is more a extra layer on top of normal logging api, to provide more sophisticated feature like i18n etc.

JBoss-logging can use other logging library (e.g. SLF4J) as the underlying handler for log.

I believe if you are writing a simple standalone Java app, you do not need to use JBoss-logging (unless you know you really want and need to do so).

Using SLF4J (with LogBack or Log4J binding) will be a good choice. Visit http://slf4j.org for more information

like image 42
Adrian Shum Avatar answered Oct 19 '22 23:10

Adrian Shum


Make sure you have jboss-logging and your logger implementation in your classpath and set the system property org.jboss.logging.provider to log4j, jdk, slf4j or jboss depending on what you want. In theory autodetection may also work.

https://github.com/jboss-logging/jboss-logging/blob/master/src/main/java/org/jboss/logging/LoggerProviders.java#L29

like image 36
Philippe Marschall Avatar answered Oct 20 '22 00:10

Philippe Marschall