[JBoss]-SQL method for printing hibernate in JBoss 7.1 as

Source: Internet
Author: User
Tags system log jboss log4j

Because JBoss uses Log4j,jboss, the system log level by default is info. Hibernate or Ibatis to print SQL, level debug, so the program set the log4j level for debug will be installed by the JBoss system info to be overwritten.

To resolve this issue, you need to manually configure the log4j logging level for JBoss:

1. Open File: Jboss-as-7.1.1.final\standalone\configuration\standalone.xml

2. Locate this node:

<xmlns= "urn:jboss:domain:logging:1.1">::</ Subsystem >

3, put Console-handler <level name= "INFO"/>

4. In the following pile of logger, join these:

            <Loggercategory= "Org.hibernate.SQL">                < Levelname= "DEBUG"/>            </Logger>            <Loggercategory= "Org.hibernate.ps.PreparedStatementCache">                < Levelname= "DEBUG"/>            </Logger>            <Loggercategory= "Org.hibernate.type">                < Levelname= "TRACE"/>            </Logger>

Save to exit.

This is all of the contents of the <subsystem/> node:

        <Subsystemxmlns= "urn:jboss:domain:logging:1.1">            <Console-handlername= "CONSOLE">                <Filter>                    < not>                        <Matchpattern= "jbas011054| JBAS011006 "/>                    </ not>                </Filter>                <Formatter>                    <Pattern-formatterpattern= "%d{hh:mm:ss,sss}%-5p [%c] (%t)%s%e%n"/>                </Formatter>            </Console-handler>            <Periodic-rotating-file-handlername= "FILE">                <Formatter>                    <Pattern-formatterpattern= "%d{hh:mm:ss,sss}%-5p [%c] (%t)%s%e%n"/>                </Formatter>                <filerelative-to= "Jboss.server.log.dir"Path= "Server.log"/>                <suffixvalue= ". Yyyy-mm-dd"/>                <Appendvalue= "true"/>            </Periodic-rotating-file-handler>            <Loggercategory= "Com.arjuna">                < Levelname= "WARN"/>            </Logger>            <Loggercategory= "Org.apache.tomcat.util.modeler">                < Levelname= "WARN"/>            </Logger>            <Loggercategory= "Sun.rmi">                < Levelname= "WARN"/>            </Logger>            <Loggercategory= "Jacorb">                < Levelname= "WARN"/>            </Logger>            <Loggercategory= "Jacorb.config">                < Levelname= "ERROR"/>            </Logger>            <Loggercategory= "Org.hibernate.SQL">                < Levelname= "DEBUG"/>            </Logger>            <Loggercategory= "Org.hibernate.ps.PreparedStatementCache">                < Levelname= "DEBUG"/>            </Logger>            <Loggercategory= "Org.hibernate.type">                < Levelname= "TRACE"/>            </Logger>            <Root-logger>                < Levelname= "INFO"/>                <handlers>                    <Handlername= "CONSOLE"/>                    <Handlername= "FILE"/>                </handlers>            </Root-logger>        </Subsystem>

There is one in Console-handler: <match pattern= "jbas011054| JBAS011006 "/>

It means to filter out some of the JBoss error messages, or you will see some "boring" exception messages at JBoss startup, which is an eyesore.

Configuration information for log4j:

##########################################################log4j setting level and what kind of log to output######################################################### #log4j. Rootcategory=info, stdout,filelog4j. Rootlogger=info, STDOUT,file##########################################################turn on the log level required to output to the specified module#########################################################log4j. logger.org.springframework=errorlog4j. logger.org.hibernate=INFOlog4j. logger.org.apache.struts2=errorlog4j. logger.org.hibernate.sql=DEBUGlog4j. logger.org.hibernate.ps.preparedstatementcache=warnlog4j. logger.org.hibernate.type=TRACE##########################################################Console Output#########################################################log4j. appender.stdout=org.apache.log4j.consoleappenderlog4j. Appender.stdout.target=system.outlog4j. appender.stdout.layout=org.apache.log4j.patternlayoutlog4j. APPENDER.STDOUT.LAYOUT.CONVERSIONPATTERN=[%D{YYYY-MM-DD HH: Mm:ss}]%m%nlog4j. appender.stdout.threshold=TRACE##########################################################file Output#########################################################log4j. appender.file=org.apache.log4j.dailyrollingfileappenderlog4j. Appender.file.file=${webapp.root}/web-inf/log/loginfo.loglog4j. appender.file.encoding=utf-8log4j. appender.file.datepattern= '. ' Yyyy-mm-dd '.log ' log4j. appender.file.layout=org.apache.log4j.patternlayoutlog4j. APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=[%D{YYYY-MM-DD HH: Mm:ss}]%m%nlog4j. appender.file.bufferedio=false#log4j. appender.file.buffersize=1024

Final output Result:

[JBoss]-SQL method for printing hibernate in JBoss 7.1 as

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.