You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by bu...@apache.org on 2008/09/14 12:52:50 UTC

DO NOT REPLY [Bug 45803] New: Add custom JUL LogManager to activate JUL Bridge

https://issues.apache.org/bugzilla/show_bug.cgi?id=45803

           Summary: Add custom JUL LogManager to activate JUL Bridge
           Product: Log4j
           Version: 1.2
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Other
        AssignedTo: log4j-dev@logging.apache.org
        ReportedBy: javabrett@gmail.com


As per discussion on the mailing list.

With JUL it is possible to use a system property to control the
LogManager class.  So I created a class:

   /* *** */
   package org.apache.logging.julbridge;

   import java.io.IOException;

   import org.apache.log4j.LogManager;

   public class JULBridgeLogManager extends java.util.logging.LogManager {

       public void readConfiguration() throws IOException, SecurityException {
           JULLog4jBridge.assimilate(LogManager.getLoggerRepository());
       }
   }

Then, I can set
-Djava.util.logging.manager=org.apache.logging.julbridge.JULBridgeLogManager
for my JVM startup, and the bridge is activated on the first call to
the LogManager, when a Logger is first requested.  There seems to be
sufficient synchronization protection around this.

This works for me and avoids a) the initial JUL LogManager
initialization (minor) and b) the need for a static call to activate
the bridge, nicely replaced with a system property.

Candidate patch attached.  This code is "all yours".


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 45803] Add custom JUL LogManager to activate JUL Bridge

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45803


Paul Smith <ps...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




--- Comment #2 from Paul Smith <ps...@apache.org>  2008-09-14 20:08:11 PST ---
Fixed in revision 695336, thanks!

Couldn't work out how to trick JUL to allow me to write a unit test for this
though, because the static block in j.u.l.LogManager reads the system property
early, so defeats my ability to 'activate' that feature in a single unit test. 
Ideas on evil-hacking to build a test case appreciated.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 45803] Add custom JUL LogManager to activate JUL Bridge

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45803





--- Comment #1 from Brett Randall <ja...@gmail.com>  2008-09-14 03:53:59 PST ---
Created an attachment (id=22562)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=22562)
Candidate patch.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


DO NOT REPLY [Bug 45803] Add custom JUL LogManager to activate JUL Bridge

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=45803





--- Comment #3 from Brett Randall <ja...@gmail.com>  2008-09-17 15:43:07 PST ---
I think that evil hacking would involve getting into jUnit's test case class
reloading capabilities, forcing a fresh classloader to load the particular test
case.

This is all that can be done, as LogManager references the system property
during its static initialization, so if will have to be reloaded in order to
test it.

Bumping up to jUnit4 might assist, as might playing with jUnit's "loading"
property in its BaseTestRunner class.

Cheers
Brett


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org