Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeMidnight
<logback.version>1.2.3</logback.version> 
<dependency>
	<groupId>ch.qos.logback</groupId>
	<artifactId>logback-core</artifactId>
	<version>${logback.version}</version>
</dependency>
<dependency>
	<groupId>ch.qos.logback</groupId>
	<artifactId>logback-classic</artifactId>
	<version>${logback.version}</version>
</dependency> 
<dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.version}</version>
</dependency>

...

Code Block
languagejava
themeMidnight
    @Override
    public Boolean health(HttpServletRequest servletRequest) {
    	Boolean health = true;
      	  // TODO: check database notice no logging commands here
    	//LoggerFactory.getLogger(ApplicationService.class).info("Start /health")return health;
    	//final ONAPLogAdapter adapter = new ONAPLogAdapter(LoggerFactory.getLogger(this.getClass()));
    	//try {
    	//    adapter.entering(new ONAPLogAdapter.HttpServletRequestAdapter(servletRequest));
    	//} finally {
    	//    adapter.exiting();
    	//}
    	return health;
    }

Aspect References

}


Aspect References

Code Block
languagejava
themeMidnight
package org.onap.demo.logging;
import javax.servlet.http.HttpServletRequest;
import org.aspectj.
Code Block
languagejava
themeMidnight
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.onap.logging.ref.slf4j.ONAPLogAdapter;
import org.slf4j.LoggerFactory;

@Aspect
public class LoggingAspect {
    private final ONAPLogAdapter adapter = new ONAPLogAdapter(LoggerFactory.getLogger(this.getClass()));
    
    @Before("execution(* org.onap@Before("execution(* org.onap.demo.logging.*.*(..))")
    public void logBefore(JoinPoint joinPoint) {
        //final ONAPLogAdapter adapterObject[] args = new ONAPLogAdapter(LoggerFactory.getLogger(this.getClass())joinPoint.getArgs();
        LoggerFactory.getLogger(ApplicationService.class).info("Starting /health");
        try {Object servletRequest = args[0];
        ONAPLogAdapter.HttpServletRequestAdapter requestAdapter   //adapter.entering(= new ONAPLogAdapter.HttpServletRequestAdapter(servletRequest));
        }         (HttpServletRequest)servletRequest);
        final ONAPLogAdapter adapter = new ONAPLogAdapter(LoggerFactory.getLogger(joinPoint.getTarget().getClass()));
        try {
            adapter.entering(requestAdapter);
        } finally {
            adapter.exiting();
        }
    }
}

results - still working on passing in the servlet request
INFO: Server startup in 10663 ms
2018-07-09T01:0637:3045.837Z402Z	http-nio-8080-exec-2	INFO	org.onap.demo.logging.ApplicationService		Starting /health		InstanceUUID=da6befe8-3199-4cf1-80e8-22dd8c2356ce, RequestID=a6e590e0-7330-4751-bdbc-f367e5757d87, ServiceName=/logging-demo/rest/health/health, InvocationID=8f674cf3-823c-40a9-92d3-dad45490e141, InvokeTimestamp=2018-07-09T01:37:45.397Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost			ENTRY	
2018-07-09T01:0637:3045.841Z403Z	http-nio-8080-exec-2	INFO	org.onap.demo.logging.LoggingAspectApplicationService	ResponseCode=, InstanceUUID=da6befe8-3199-4cf1-80e8-22dd8c2356ce, RequestID=a6e590e0-7330-4751-bdbc-f367e5757d87, ServiceName=/logging-demo/rest/health/health, ResponseDescription=, InvocationID=8f674cf3-823c-40a9-92d3-dad45490e141, Severity=, InvokeTimestamp=2018-07-09T01:37:45.397Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost, StatusCode=			EXIT	

Without Spring AOP

Code Block
languagejava
themeMidnight
# pending annotation level weaving of the library
import org.onap.logging.ref.slf4j.ONAPLogAdapter;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@Service("daoFacade")
public class ApplicationService implements ApplicationServiceLocal {
    @Override
    public Boolean health(HttpServletRequest servletRequest) {
    	Boolean health = true;
    	// TODO: check database
    	final ONAPLogAdapter adapter = new ONAPLogAdapter(LoggerFactory.getLogger(this.getClass()));
    	try {
    	    adapter.entering(new ONAPLogAdapter.HttpServletRequestAdapter(servletRequest));
    	} finally {
    	    adapter.exiting();
    	}
    	return health;
    }
MDC's are set for example


this	LogbackMDCAdapter  (id=282)	
	copyOnInheritThreadLocal	InheritableThreadLocal<T>  (id=284)	
	lastOperation	ThreadLocal<T>  (id=287)	
key	"ServerFQDN" (id=273)	
val	"localhost" (id=272)	


{InstanceUUID=aa2d5b18-e3c2-44d3-b3ae-8565113a81b9, RequestID=788cf6a6-8008-4b95-af3f-61d92d9cbb4e, ServiceName=, InvocationID=dade7e58-fa24-4b2d-84e8-d3e89af9e6e1, InvokeTimestamp=2018-07-05T14:25:05.739Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost}


in	
LogbackMDCAdapter.put(String, String) line: 98	
MDC.put(String, String) line: 147	
ONAPLogAdapter.setEnteringMDCs(RequestAdapter<?>) line: 327	
ONAPLogAdapter.entering(ONAPLogAdapter$RequestAdapter) line: 156	
ApplicationService.health(HttpServletRequest) line: 38	
RestHealthServiceImpl.getHealth() line: 47	

# fix
get() returned	"" (id=201)	
key	"ServiceName" (id=340)	

Daemon Thread [http-nio-8080-exec-12] (Suspended)	
	owns: NioEndpoint$NioSocketWrapper  (id=113)	
	MDC.get(String) line: 203	
	ONAPLogAdapter.setEnteringMDCs(RequestAdapter<?>) line: 336	
	ONAPLogAdapter.entering(ONAPLogAdapter$RequestAdapter) line: 156	
	ApplicationService.health(HttpServletRequest) line: 38	
	RestHealthServiceImpl.getHealth() line: 47	

        if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null) {
            MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, request.getRequestURI());

to
        if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null ||
                MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME).equalsIgnoreCase(EMPTY_MESSAGE)) {

...