RestComm / Restcomm-Connect

The Open Source Cloud Communications Platform
http://www.restcomm.com/
GNU Affero General Public License v3.0
240 stars 214 forks source link

NIST stack custom logger "gov.nist.javax.sip.STACK_LOGGER" provides class context #3012

Open gidxl03 opened 3 years ago

gidxl03 commented 3 years ago

/kind feature

What happened: The class context of the logger is lost when supplying a custom implementation of gov.nist.core.StackLogger, because gov.nist.core.CommonLogger variable 'name' is never passed to the logger.

What you expected to happen: The NIST stack logs include the name of the logger Example

Time [Thread-name] DEBUG gov.nist.javax.sip.stack.SIPDialog - isBackToBackUserAgent = false and not Time [Thread-name] DEBUG - isBackToBackUserAgent = false

How to reproduce it (as minimally and precisely as possible): Provide an implementation of gov.nist.core.StackLogger using a Logger such as Log4j2 and set property gov.nist.javax.sip.STACK_LOGGER to MyCustomStackLogger.class.getName()

Anything else we need to know?: Note that gov.nist.core.CommonLogger will create a new CommonLogger instance with the name of the logging class but the name is never used and CommonLogger adds no value.

Environment: All Environments

gidxl03 commented 3 years ago

I would like to be added as a contributor, github profile gidxl03. I have a working solution

Add default interface method

public interface StackLogger extends LogLevels {
    /**
     * Invoked on first usage of the logger
     * @param clazz
     * @return instance of the stack logger for the given class
     */
    default StackLogger getLoggerInstance(Class<?> clazz) {return this;}

Modify existing method in StackLogger

    public static StackLogger getLogger(Class<?> clazz) {
        if (useLegacyLogger && legacyLogger != null) {
            return legacyLogger.getLoggerInstance(clazz);
        }
        return getLogger(clazz.getName());
    }

Rejected Solution Application creates ‘gov.nist.core.CommonLoggerLog4j’ with a custom implementation and loads it first in the classpath