Question

I am using log4j2.xml for my web application and it is working fine. the problem is, it is printing all the domain information also. i am using hibernate+spring.Since the domain contains the user class it is printing the password also in the log file.. My log4j.xml is below..

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="trace">
    <appenders> 
            <RollingRandomAccessFile name="ONBOARDING_LOG" fileName="C:/jetty-distribution-9.0.6.v20130930/logs/onboarding.log" filePattern="C:/jetty-distribution-9.0.6.v20130930/logs/onboarding.log.%i" append="true" immediateFlush="true">
                    <PatternLayout>
                            <pattern>%d{ISO8601} %-5p [%t]: [%c{1}] %m%n-%X{ElapsedTime}-%X{ByteSize}-%X{uniqueID}-%X{HttpMethod}-%X{URL}-</pattern>
                    </PatternLayout>
                    <Policies>
                            <SizeBasedTriggeringPolicy size="250 MB"/>
                    </Policies>
                    <DefaultRolloverStrategy max="10"/>
            </RollingRandomAccessFile>
    </appenders>

   <loggers>

            <root level="DEBUG">
                    <appender-ref ref="ONBOARDING_LOG"/>
            </root>
    </loggers>

and my session-factory.xml is as...

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>java:comp/env/jdbc/Onboarding</value>
    </property>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

    <property name="dataSource" ref="dataSource" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        </props>
    </property>
    <property name="packagesToScan">
        <list>
            <value>biz.neustar.onboarding.domain</value>
        </list>
    </property>

</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

and the message from the log file is....

 [Printer] listing entities:
     ------2014-03-06 13:35:59,178 DEBUG [qtp19318917-21:http://0:0:0:0:0:0:0:1:8080/OnBoarding/index.do]:             [Printer] biz.neustar.onboarding.domain.User{lastName=TP, updatedDate=2014-02-28 20:12:02,   companyName=TurningPoint, password=admin, userOid=1, phoneNo=1.234567890, isLogged=Y, organizationStagingList=<uninitialized>, email=admin@tpgsi.com, userStatus=biz.neustar.onboarding.domain.UserStatus#1, userName=admin, firstName=Admin, createdDate=2007-05-06 00:00:00, userAccess=biz.neustar.onboarding.domain.UserAccess#1}
      ------2014-03-06 13:35:59,178 DEBUG [qtp19318917-21:http://0:0:0:0:0:0:0:1:8080/OnBoarding/index.do]: [Printer] biz.neustar.onboarding.domain.UserAccess{users=<uninitialized>, accessId=1, accessType=ADMINISTRATOR}
     ------2014-03-06 13:35:59,178 DEBUG [qtp19318917-21:http://0:0:0:0:0:0:0:1:8080/OnBoarding/index.do]: [Printer] biz.neustar.onboarding.domain.UserStatus{statusId=1, users=<uninitialized>, statusType=ACTIVE}
Was it helpful?

Solution

The problem is hibernate internally uses log4j to log the message. I got to know this by seeing the logs which contains Printer and it is final class defined in hibernate so i made some changes in the log4j.xml. and it should be added before the root level...I hope this will be very helpful for others and other comments will be highly appreciated..thanks

 <loggers>
    <logger name="org.hibernate.pretty">
            <level value="OFF" />
    </logger>

    <logger name="org.hibernate.SQL">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.secure">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.hql.ast.AST">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.jdbc">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.transaction">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.tool.hbm2ddl">
        <level value="OFF"/>
    </logger>

    <logger name="org.hibernate.type">
              <level value="OFF"/>
    </logger>       

OTHER TIPS

I think what you are seeing in the first section between square brackets ([qtp19318917-21:http://0:0:0:0:0:0:0:1:8080/OnBoarding/index.do]) is the thread name.

If this values is too long you can change the [%t] in the layout pattern with [%.30t] to specify you want maximum 30 characters. (http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout )

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top