You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Nathan Niesen (JIRA)" <ji...@apache.org> on 2009/10/22 20:16:59 UTC

[jira] Created: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Jdk14Logger wrapper does not respect logger name
------------------------------------------------

                 Key: LOGGING-132
                 URL: https://issues.apache.org/jira/browse/LOGGING-132
             Project: Commons Logging
          Issue Type: Bug
    Affects Versions: 1.1.1, 1.1.0, 1.0.4, 1.0.3, 1.0.1, 1.0, Nightly Builds, 2.0
            Reporter: Nathan Niesen
            Priority: Minor


The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. It is also problematic for obfuscated code and private parts of an application or library.

Example:
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message

With the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message


The fix:

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Nathan Niesen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Niesen updated LOGGING-132:
----------------------------------

    Description: 
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.

<b>Example:</b>
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

<blockquote>
    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message
</blockquote>

With the JDK log wrapper, I get something like:

<blockquote>
    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message
</blockquote>

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

</blockquote>
    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message
</blockquote>

<b>The fix:</b>

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }


  was:
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. It is also problematic for obfuscated code and private parts of an application or library.

Example:
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message

With the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message


The fix:

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }



> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 2.0
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> <b>Example:</b>
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
> <blockquote>
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> </blockquote>
> With the JDK log wrapper, I get something like:
> <blockquote>
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> </blockquote>
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
> </blockquote>
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> </blockquote>
> <b>The fix:</b>
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Nathan Niesen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Niesen updated LOGGING-132:
----------------------------------

    Affects Version/s: 2.0
                       1.1.2
                       1.0.2

> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 1.1.2, 2.0
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Dennis Lundberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dennis Lundberg updated LOGGING-132:
------------------------------------

    Affects Version/s:     (was: 2.0)

Removing 2.0 as "Affects version/s" again. That is only a placeholder for ideas at this time, so this issue can't have an effect that version.

> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 1.1.2
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Nathan Niesen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805540#action_12805540 ] 

Nathan Niesen commented on LOGGING-132:
---------------------------------------

If there is a major impact, it's because there are a lot of bad tests. ;-)

The real impact will be that the logger implementation adheres to the contract set forth in the JDK and Commons logging documentation. The logger is created with a specified string name (not a class name), configured using the specified name, and logs using the specified name. Nothing in the LogFactory uses an object instances class name to retrieve a logger or change its implementation.

I should also note that the Jdk13LumberjackLogger appears to have a similar defect. The implementation of its log method is different but it creates a LogRecord and never calls setLoggerName(this.name).

The Avalon and Log4J loggers use the Logger class and which correctly sets the logger name on the log record. SimpleLog also correctly uses the log name.

> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Nathan Niesen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12805540#action_12805540 ] 

Nathan Niesen edited comment on LOGGING-132 at 1/27/10 3:36 PM:
----------------------------------------------------------------

If there is a major impact, it's because there are a lot of bad tests. ;-)

The real impact will be that the logger implementation adheres to the contract set forth in the JDK and Commons logging documentation. The logger is created with a specified string name (not a class name), configured using the specified name, and logs using the specified name. Nothing in the LogFactory uses an object instances class name to retrieve a logger or change its configuration.

I should also note that the Jdk13LumberjackLogger appears to have a similar defect. The implementation of its log method is different but it creates a LogRecord and never calls setLoggerName(this.name).

The Avalon and Log4J loggers use the Logger class and which correctly sets the logger name on the log record. SimpleLog also correctly uses the log name.

      was (Author: nathann@objectfx.com):
    If there is a major impact, it's because there are a lot of bad tests. ;-)

The real impact will be that the logger implementation adheres to the contract set forth in the JDK and Commons logging documentation. The logger is created with a specified string name (not a class name), configured using the specified name, and logs using the specified name. Nothing in the LogFactory uses an object instances class name to retrieve a logger or change its implementation.

I should also note that the Jdk13LumberjackLogger appears to have a similar defect. The implementation of its log method is different but it creates a LogRecord and never calls setLoggerName(this.name).

The Avalon and Log4J loggers use the Logger class and which correctly sets the logger name on the log record. SimpleLog also correctly uses the log name.
  
> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Dennis Lundberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Dennis Lundberg updated LOGGING-132:
------------------------------------

          Description: 
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.

Example:
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message

With the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message

The fix:

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.

{code}
    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }
{code}


  was:
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.

Example:
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message

With the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message

The fix:

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }


    Affects Version/s:     (was: 2.0)

> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Dennis Lundberg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795189#action_12795189 ] 

Dennis Lundberg commented on LOGGING-132:
-----------------------------------------

I tried your suggestion, but there were a lots of test failures.
So changing this will have a larger impact than you thought.

> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
> {code}
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (LOGGING-132) Jdk14Logger wrapper does not respect logger name

Posted by "Nathan Niesen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LOGGING-132?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Nathan Niesen updated LOGGING-132:
----------------------------------

    Description: 
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.

Example:
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message

With the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message

The fix:

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }


  was:
The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.

<b>Example:</b>
I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").

With the other log wrappers, if I log a message I always get something like:

<blockquote>
    Oct 21, 2009 5:03:26 PM
    [INFO] SubSystemA start - My log message
</blockquote>

With the JDK log wrapper, I get something like:

<blockquote>
    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
    INFO: My log message
</blockquote>

Or worse yet with obfuscated code and the JDK log wrapper, I get something like:

</blockquote>
    Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
    INFO: My log message
</blockquote>

<b>The fix:</b>

In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.


    private void log( Level level, String msg, Throwable ex ) {

        Logger logger = getLogger();
        if (logger.isLoggable(level)) {
            // Hack (?) to get the stack trace.
            Throwable dummyException=new Throwable();
            StackTraceElement locations[]=dummyException.getStackTrace();
            // Caller will be the third element
            String cname="unknown";
            String method="unknown";
            if( locations!=null && locations.length >2 ) {
                StackTraceElement caller=locations[2];
                cname=caller.getClassName();
                method=caller.getMethodName();
            }
            if( ex==null ) {
                logger.logp( level, cname, method, msg );
            } else {
                logger.logp( level, cname, method, msg, ex );
            }
        }

    }



> Jdk14Logger wrapper does not respect logger name
> ------------------------------------------------
>
>                 Key: LOGGING-132
>                 URL: https://issues.apache.org/jira/browse/LOGGING-132
>             Project: Commons Logging
>          Issue Type: Bug
>    Affects Versions: Nightly Builds, 1.0, 1.0.1, 1.0.3, 1.0.4, 1.1.0, 1.1.1, 2.0
>            Reporter: Nathan Niesen
>            Priority: Minor
>
> The JDK14 wrapper implementation logs using the callers class name instead of the configured logger name. This prevents the ability to use named loggers for applications and subsystems. Also, the log message name does not match the JDK logger name so user don't know what name to use to configure the logger. It is also problematic for obfuscated code and private parts of an application or library.
> Example:
> I have a class named com.myco.product.subsysa.ClassX.InnerClassY and I create logger LogFactory.getLog("SubSystemA").
> With the other log wrappers, if I log a message I always get something like:
>     Oct 21, 2009 5:03:26 PM
>     [INFO] SubSystemA start - My log message
> With the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$InnerClassY start
>     INFO: My log message
> Or worse yet with obfuscated code and the JDK log wrapper, I get something like:
>     Oct 21, 2009 5:03:26 PM com.myco.product.subsysa.ClassX$_oOOO.o00000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000
> 00000000000000000000000000000000000000000000000000000000
>     INFO: My log message
> The fix:
> In the calls to logger.logp(...), replace cname with this.name. Loggers created with the class name will still get the class name.
>     private void log( Level level, String msg, Throwable ex ) {
>         Logger logger = getLogger();
>         if (logger.isLoggable(level)) {
>             // Hack (?) to get the stack trace.
>             Throwable dummyException=new Throwable();
>             StackTraceElement locations[]=dummyException.getStackTrace();
>             // Caller will be the third element
>             String cname="unknown";
>             String method="unknown";
>             if( locations!=null && locations.length >2 ) {
>                 StackTraceElement caller=locations[2];
>                 cname=caller.getClassName();
>                 method=caller.getMethodName();
>             }
>             if( ex==null ) {
>                 logger.logp( level, cname, method, msg );
>             } else {
>                 logger.logp( level, cname, method, msg, ex );
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.