Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gidxl03 opened this issue Dec 28, 2020 · 1 comment

Comments

@gidxl03
Copy link

gidxl03 commented Dec 28, 2020

/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
Copy link
Author

gidxl03 commented Dec 28, 2020

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

  • minimal code change
  • backwards compatible
  • requires jain-sip-ri POM change from Java 1.7 (EOL) to 1.8 to avail of default interfaces

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant