Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 319484

Summary: Setting log handler (java.util.logging.FileHandler.formatter) ignored
Product: [Eclipse Project] JDT Reporter: kcassell2001
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, darin.eclipse, Michael_Rennie, Olivier_Thomann
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Specifies the log properties
none
A modified SampleAction for HelloWorld
none
Log file when run as a Java app
none
Log file when run as a plug-in
none
The custom log formatter none

Description kcassell2001 CLA 2010-07-11 04:44:36 EDT
Build Identifier: Version: 3.5.2 Build id: M20100211-1343

I have legacy code that I want to be able to use both within the plug-in and in the old standalone code. This code uses java.util.logging.  I want to use a custom log handler.  

I debug my plug-in by starting up a new workbench using a JVM option "-Djava.util.logging.config.file=c:/logging.properties".  The logging.properties file appears to be read, because the file specified by java.util.logging.FileHandler.pattern is being written. Unfortunately, the custom formatter that I specified via java.util.logging.FileHandler.formatter does not seem to get called; the output in the file is in what looks to be a default XML format. The logging works okay in the legacy code, i.e., my custom formatter gets used.

Reproducible: Always

Steps to Reproduce:
1. Create a HelloWorld plug-in
2. Add some logging using java.util.logging.Logger
3. Create an Eclipse Application debug configuration.
4. Add a VM argument - "-Djava.util.logging.config.file=c:/logging.properties"
5. Within logging.properties, add a line specifying a custom formatter, e.g. "java.util.logging.FileHandler.formatter = nz.ac.vuw.ecs.kcassell.logging.ConciseLogFormatter"
6. Run the debug configuration.  Log messages will be in an XML format.
Comment 1 kcassell2001 CLA 2010-07-11 04:46:44 EDT
Created attachment 173965 [details]
Specifies the log properties
Comment 2 kcassell2001 CLA 2010-07-11 04:49:28 EDT
Created attachment 173966 [details]
A modified SampleAction for HelloWorld
Comment 3 kcassell2001 CLA 2010-07-11 04:51:37 EDT
Created attachment 173967 [details]
Log file when run as a Java app

If I run the SampleAction as a Java app, I get the desired log file output.
Comment 4 kcassell2001 CLA 2010-07-11 04:53:15 EDT
Created attachment 173968 [details]
Log file when run as a plug-in

If I run SampleAction from the spawned workspace, I get the undesirable XML log file.
Comment 5 kcassell2001 CLA 2010-07-11 04:54:57 EDT
Created attachment 173969 [details]
The custom log formatter
Comment 6 Olivier Thomann CLA 2010-07-12 08:49:22 EDT
Moving to JDT/Debug.
Comment 7 Michael Rennie CLA 2010-07-12 09:50:27 EDT
Adding Curtis for a comment from PDE. Is there anything special PDE does around logging or the like?
Comment 8 Curtis Windatt CLA 2010-07-12 14:29:50 EDT
PDE owns the log view, but it hooks into the Eclipe logging framework, not with java's logging utils.  Since the file is getting pinged, it seems likely the java logger is having trouble parsing the properties file into a proper formatter.  This does not look like an Eclipse bug.
Comment 9 kcassell2001 CLA 2010-07-12 16:38:50 EDT
(In reply to comment #8)
> PDE owns the log view, but it hooks into the Eclipe logging framework, not with
> java's logging utils.  Since the file is getting pinged, it seems likely the
> java logger is having trouble parsing the properties file into a proper
> formatter.  This does not look like an Eclipse bug.

I don't follow your analysis.  First, if I run the SampleAction as a Java app, I get correct behavior as shown by the second attached log file.  Second, when run as a plug-in, at least some of the properties file is being read correctly, because the log file is showing up in the correct location as specified in the properties file.  So, what is it that makes you say it looks like a Java bug and not an Eclipse bug?

As a wild guess on my part, is there some exotic class-loading that occurs when debugging plug-ins?
Comment 10 Darin Wright CLA 2010-07-14 16:37:30 EDT
(In reply to comment #9)
> As a wild guess on my part, is there some exotic class-loading that occurs when
> debugging plug-ins?

Yes - an OSGi class loader is used when running/debugging plug-ins. When run as a plain java application, I assume the logger is found on the runtime classpath. When run as an OSGi app, there is no runtime classpath as such... OSGi instead knows which bundles are to be run, and each bundle gets a class loader.
Comment 11 Darin Wright CLA 2010-07-14 16:42:56 EDT
Perhaps this helps:

http://dev.eclipse.org/newslists/news.eclipse.platform/msg68257.html
Comment 12 Darin Wright CLA 2010-07-14 16:43:14 EDT
Marking as won't fix.