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 2013/04/07 06:08:21 UTC

[Bug 54809] New: Loader.getResource(String) and Loader.loadClass(String) should apply separate ignoreTCL option

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

            Bug ID: 54809
           Summary: Loader.getResource(String) and
                    Loader.loadClass(String) should apply separate
                    ignoreTCL option
           Product: Log4j
           Version: 1.2.17
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: Configurator
          Assignee: log4j-dev@logging.apache.org
          Reporter: sonotwind@sohu.com
    Classification: Unclassified

appliction server: glassfish3.1.2.2

the deployed structure of EAR:
/lib
--/log4j.jar
--/openjpa-2.2.1.jar
--/project-entity.jar
--/...
/project-ejb.jar
/project-web.war
/project-ejb_jar
--/log4j.properties
--/...
/project-web_war
--/WEB-INF
--/META-INF

log4j.properties:
log4j.rootLogger=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c - %m%n

when log4j.ignoreTCL is false, log4j.propeties can be found, but
org.apache.log4j.Appender and org.apache.log4j.ConsoleAppender are loaded by
different class loader. when log4j.ignoreTCL is true, org.apache.log4j.Appender
and org.apache.log4j.ConsoleAppender are loaded by same class loader, but
log4j.propeties cann't be found.

I suggest adding ignoreTCLForResource and ignoreTCLForClass options, and
modifying org.apache.log4j.helpers.Loader to this:

// add two class variables
static private boolean ignoreTCLForResource = false;
static private boolean ignoreTCLForClass = false;

// add code in static block
static
{
    ...;

    String value =
OptionConverter.getSystemProperty("log4j.ignoreTCLForResource", null);
    ignoreTCLForResource = value == null ? ignoreTCL :
OptionConverter.toBoolean(value, true); 

    value = OptionConverter.getSystemProperty("log4j.ignoreTCLForClass", null); 
    ignoreTCLForClass = value == null ? ignoreTCL :
OptionConverter.toBoolean(value, true);                
}

// apply ignoreTCLForClass
static public Class loadClass (String clazz) throws ClassNotFoundException 
{
    if(java1 || ignoreTCLForClass) 
    {
       return Class.forName(clazz);        
    } else
    {
       ...;
    }
    return Class.forName(clazz);
}

// apply ignoreTCLForResource
static public URL getResource(String resource) 
{
    ...;

    if(!java1 && !ignoreTCLForResource) 
    {
       classLoader = getTCL();
       if(classLoader != null) 
       {
            LogLog.debug("Trying to find ["+resource+"] using context
classloader "+classLoader+".");
            url = classLoader.getResource(resource);          
            ...;
       }

    ...;
}

-- 
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


[Bug 54809] Loader.getResource(String) and Loader.loadClass(String) should apply separate ignoreTCL option

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

Eckel Dong <so...@sohu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|1.2.17                      |1.2.18

-- 
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