Pregunta

I made a simple Hibernate 3.1 java code (in eclipse) which successfully creates a table in a database. I have slfj-api-1.6.0.jar and slfj-simple-1.6.0.jar in my project. But, I don't see any Log4j logging warnings or messages in the console output. How do I make log4j log things to my console ?

My tutorial says that one of the lines I should get in the console is -

log4j.logger.org.hibernate.type = debug

I saw a couple of posts online which tell me to place a Log4j.properties file in my java project, either in src folder, or make a resources folder inside src and put it there. I found one Log4j.properties in my computer and placed it in the resources folder. I am not sure if I should use the settings in that file or how to edit this file as per my requirement. How do I do this correctly ?

EDIT -

The log4j.properties file -

### Direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - ###
log4j.rootLogger=warn, stdout log4j.logger.org.hibernate.info

### log JDBC bind parameters ###
log4j.logger.org.hibernate.type=debug

###log schema export/update ###
log4j.logger.org.hibernate.tool.hbm2ddl=debug

Thanks.

¿Fue útil?

Solución

First of all, the file name must be in lowercase. The Log4j.properties file is wrong, it's log4j.properties. This must be put in the root folder of your project (in most cases the src folder).

Secondly, you need to download the log4j jar file if you want to use SLF4J bridge with log4j. Download the latest library that you require from Apache Logging Services. Don't forget that there are 2 versions of Apache Log4J, so I suggest you try version 1.x first.

Good luck!

Otros consejos

One thing to note is that the file should be called log4j.properties and should be placed in the root of your src or resource folder (by default at least) ... you seem to be calling it Log4j.properties

I also think that you are missing the following dependency:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.1</version>
    </dependency>

The resources folder is only an option if you identify it as a source folder on the project properties!java build path!source tab.

Slf4j does not use log4j to write to the logs unless you include the slf4j-log4j[version].jar (for example, slf4j-log4j12-1.7.7.jar) jar in your project. If you include this jar, then you must not include the slfj-simple-1.6.0.jar jar in your project.

Here is a link to the slf4j online manual

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top