Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » How to change output of DefaultSessionLog to file through SessionCustomizer
How to change output of DefaultSessionLog to file through SessionCustomizer [message #381394] Mon, 22 September 2008 18:10 Go to next message
Bill Blalock is currently offline Bill Blalock
Messages: 118
Registered: July 2009
Location: Alabama
Senior Member
What is the correct way to change the output of DefaultSessionLog from
stdout to a file using a subclass of SessionCustomizer?

in these examples the String logFilename = "eclipselink.log"

First I tried:
session.setLog(new OutputStreamWriter(
new FileOutputStream( logFilename )));

Then I tried:
SessionLog sessionLog = new DefaultSessionLog() ;
((DefaultSessionLog)sessionLog).setWriter(logFilename);
session.setSessionLog(sessionLog);

No errors, but no eclipselink.log file either. Output still going to
stdout.

The JPA project is packaged in a jar file, the jar file is used in an
Eclipse RCP. The eclipselink.log file should be created in the .metadata
folder.

These code snippets are part of a subclass of SessionCustomizer and the
subclass is referenced in persistence.xml and is being executed.

Thanks
Bill Blalock
Re: How to change output of DefaultSessionLog to file through SessionCustomizer [message #381397 is a reply to message #381394] Tue, 23 September 2008 14:37 Go to previous messageGo to next message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
Both of those should work. Are you sure you SessionCustomizer is being
called? Did you set your customizer in your persistence.xml? Do you get
any errors logged to System.out?

You can also configure file logging using the "eclipselink.logging.file"
persistence.xml property.

-- James
Re: How to change output of DefaultSessionLog to file through SessionCustomizer [message #381398 is a reply to message #381397] Wed, 24 September 2008 00:27 Go to previous messageGo to next message
Bill Blalock is currently offline Bill Blalock
Messages: 118
Registered: July 2009
Location: Alabama
Senior Member
James wrote:

> Both of those should work. Are you sure you SessionCustomizer is being
> called? Did you set your customizer in your persistence.xml?

Yes, the session customizer is called. I put some System.out.println() to
be sure. The session customizer class sets the user, password and other
things correctly.

> Do you get any errors logged to System.out?

No, errors to System.out. Log messages after setting the log writer don't
go to System.out.

I have customizer annotations in my entities. They log warnings to
System.out before the SessionCustomizer kicks in. The messages after
changing the write don't go to System.out. Normally a couple of INFO
messages would be logged and then some messages I put into the
SessionCustomizer (to test logging) aren't appearing. I can't find a
"eclipselink.log" file.

I'll work with this some more and post what I find out.

Any suggestions as to what I should try?????

> You can also configure file logging using the "eclipselink.logging.file"
> persistence.xml property.

I am aware of that but that won't work with the way I have designed my JPA
project. This will probably end up in another post but what I am doing
now is.

- Have one JPA project which manages the java persistenance. I deploy it
by making a jar from the src folder (including the persistence XML).
- The JPA project JAR is used by a server program running on a System i
(aka AS400). The server program uses log4j for its logging. That is why
my interest in using log4j with Eclipselink (see other posts). The
logging class is set by the SessionCustomizer to use the log4j class when
the JPA project jar is being used by the server program.
- The JPA project JAR is also used by an Eclipse RCP client program. I
decided to stick with DefaultSessionLog but to write the log in the
metadata folder. No change is made to the logger class when the JPA
project jar is being used by the RCP.

That is why I need the SessionCustomizer subclass to set the log writer --
it only gets changed when the JPA project jar is used by the RCP.

The log level is set to INFO in the persistence.xml.

As I said, the log enteries go to System.out until the SessionCustomizer
subclass changes the log writer. That tells me that logging is working.

Thanks for your time.

Bill Blalock

> -- James
Re: How to change output of DefaultSessionLog to file through SessionCustomizer [message #381400 is a reply to message #381398] Wed, 24 September 2008 14:27 Go to previous messageGo to next message
James is currently offline James
Messages: 272
Registered: July 2009
Senior Member
The log seems to be working, you are probably just looking in the wrong
place for the file. Try giving a full file path, or try,

new File(fileName).getAbsolutePath()

To see where the file is going.

-- James
Re: How to change output of DefaultSessionLog to file through SessionCustomizer [message #381403 is a reply to message #381400] Wed, 24 September 2008 22:00 Go to previous message
Bill Blalock is currently offline Bill Blalock
Messages: 118
Registered: July 2009
Location: Alabama
Senior Member
Thanks James!

I did as you suggested. The log file ended up in the root of the Eclipse
install.

Laughs, I checked all the reasonable places -- even did a windows search
of the folder holding all my workspaces.

I'll specify the full path from now on. I used
Platform.getLogLocation().getFile().getParent()
to get the folder path where the RCP stores it log.

Bill Blalock
Previous Topic:DatabasePlatform file for Ingres
Next Topic:Oracle Releases Oracle® TopLink® 11g Based on EclipseLink
Goto Forum:
  


Current Time: Mon Oct 20 11:25:39 GMT 2014

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

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