Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink and Log4j
EclipseLink and Log4j [message #726190] Fri, 16 September 2011 18:40 Go to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
I tried to follow the orientation below to control eclipselink log using commonslog/log4j configuration:

http://wiki.eclipse.org/EclipseLink/Foundation/Logging (Using Log4J)

I was not able to turn on and off eclipselink messages changing log4.properties or log4.xml file.
The only way to do this was changing persistence.xml (eclipselink.logging.level) to FINE or SEVERE.

My log4.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
	<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />

		</layout>
	</appender>
	<logger name="org.eclipse.persistence">
		<level value="info" />
	</logger>
	<root>
		<priority value="error"></priority>
		<appender-ref ref="stdout" />
	</root>
</log4j:configuration>


My persistence.xml properties:


			<property name="eclipselink.logging.logger" value="org.eclipse.persistence.logging.CommonsLoggingSessionLog"/>
			<property name="eclipselink.logging.level" value="severe" />



Re: EclipseLink and Log4j [message #726859 is a reply to message #726190] Mon, 19 September 2011 18:14 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You might try debugging the code you are using in the shouldLog() method. It seems it is somehow not returning the value from the log4j logging correctly.


James : Wiki : Book : Blog : Twitter
Re: EclipseLink and Log4j [message #727718 is a reply to message #726190] Wed, 21 September 2011 21:21 Go to previous messageGo to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
Quote:
somehow not returning the value from the log4j logging correctly

You are right. The level is comming from persistence.xml and not from log4j.xml.
I put the following line in the beggining of should log method
debug("CommonsLoggingSessionLog.shouldLog : IN : category : " + category + " : " + level + " >>=" + getLogWrapper(category).getLevel() + " " + getLevelString(level) + ">>=" + getLevelString(getLogWrapper(category).getLevel())) ;

And the result is
CommonsLoggingSessionLog.shouldLog : IN : category : sql : 3 >>=7 FINE>>=[b]SEVERE[/b]

When I change to level in persistence.xml from SEVERE to FINE, the result is:
CommonsLoggingSessionLog.shouldLog : IN : category : sql : 3 >>=3 FINE>>=[b]FINE[/b]

And the log message of sql is shown using the format specified in log4j.xml. So, the format is obtained correctly, but the level not.

I'm using the same code of CommonsLoggingSessionLog published in
http://wiki.eclipse.org/EclipseLink/Foundation/Logging

What can I do to change this behaviour?

Thanks. Mauro.
Re: EclipseLink and Log4j [message #727734 is a reply to message #726190] Wed, 21 September 2011 21:21 Go to previous messageGo to next message
Mauro is currently offline MauroFriend
Messages: 79
Registered: July 2009
Member
Quote:
> somehow not returning the value from the log4j logging correctly

You are right. The level is comming from persistence.xml and not from log4j.xml.
I put the following line in the beggining of should log method

debug("CommonsLoggingSessionLog.shouldLog : IN : category : " + category + " : " + level + " >>=" + getLogWrapper(category).getLevel() + " " + getLevelString(level) + ">>=" + getLevelString(getLogWrapper(category).getLevel())) ;

And the result is

CommonsLoggingSessionLog.shouldLog : IN : category : sql : 3 >>=7 FINE>>=SEVERE

When I change to level in persistence.xml from SEVERE to FINE, the result is:

CommonsLoggingSessionLog.shouldLog : IN : category : sql : 3 >>=3 FINE>>=FINE

And the log message of sql is shown using the format specified in log4j.xml. So, the format is obtained correctly, but the level not.

I'm using the same code of CommonsLoggingSessionLog published in
http://wiki.eclipse.org/EclipseLink/Foundation/Logging

What can I do to change this behaviour?

Thanks. Mauro.
Re: EclipseLink and Log4j [message #728742 is a reply to message #727734] Fri, 23 September 2011 20:08 Go to previous message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
Unfortunately I had to change the implementation of CommonsLoggingSessionLog to make it work the way I expected.

In the method addLogger I changed the line:
this.CATEGORY_LOGGERS.put(loggerCategory, new LogWrapper(this, loggerCategory, LogFactory.getLog(loggerNameSpace)));


By this line:

this.CATEGORY_LOGGERS.put(loggerCategory, new LogWrapper(this, loggerCategory, LogFactory.getLog("org.eclipse.persistence" + "." + loggerCategory)));


And in the method shouldLog I added the 3 lines below
default:
                final LogWrapper lw = getLogWrapper(category);
                if (lw.getLog().isDebugEnabled()) { // added
                  return true;  // added 
                } // added



It is not the best solution, but it is working according to my requirementes.

I would appreciate using the original code if I could identify where is the problem.

Thanks.


Previous Topic:Update on a long property lost during a transaction with find with pessimistic read lock
Next Topic:Object: is not a known entity type.
Goto Forum:
  


Current Time: Fri Apr 19 19:55:25 GMT 2024

Powered by FUDForum. Page generated in 0.03269 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top