Versions Compared

Key

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

...

Code Block
languagejava
themeMidnight
import javax.servlet.http.HttpServletRequest;
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
    	// notice no logging commands here Log outside the AOP framework - to simulate existing component logs between the ENTRY/EXIT markers
    	return healthLoggerFactory.getLogger(this.getClass()).info("Running /health");
    }	return health;
    }
}


Aspect Aspect References

Code Block
languagejava
themeMidnight
package org.onap.demo.logging;
import javax.servlet.http.HttpServletRequest;
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 {
    @Before("execution(* org.onap.demo.logging.*.*(..))")
    public void logBefore(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        Object servletRequest = args[0];
        ONAPLogAdapter.HttpServletRequestAdapter requestAdapter = new
 ONAPLogAdapter.HttpServletRequestAdapter(
               new ONAPLogAdapter.HttpServletRequestAdapter((HttpServletRequest)servletRequest);
        final ONAPLogAdapter adapter = new ONAPLogAdapter(
                LoggerFactory.getLogger(joinPoint.getTarget().getClass()));
        try {
            adapter.entering(requestAdapter);
        } finally {
        }
    }

     adapter.exiting();@After("execution(* org.onap.demo.logging.*.*(..))")
    public void logAfter(JoinPoint joinPoint) }
    }
}

results - still working on passing in the servlet request
INFO: Server startup in 10663 ms
2018-07-09T01:37:45.402Z{
        final ONAPLogAdapter adapter = new ONAPLogAdapter(
                LoggerFactory.getLogger(joinPoint.getTarget().getClass()));
        adapter.exiting();
    }

results - still working on passing in the servlet request
INFO: Reloading Context with name [/logging-demo] is completed
2018-07-09T14:48:01.014Z	http-nio-8080-exec-8	INFO	org.onap.demo.logging.ApplicationService	
 InstanceUUID=67bc4b12-56a1-4b62-ab78-0c8ca8834383, RequestID=023af35a-b281-49c4-bf13-5167b1453780, ServiceName=/logging-demo/rest/health/health, InvocationID=94dc9e24-3722-43e5-8995-12f95e153ca3, 
 InvokeTimestamp=2018-07-09T14:48:01.008Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost			ENTRY	
2018-07-09T14:48:01.014Z	http-nio-8080-exec-28	INFO	org.onap.demo.logging.ApplicationService	
 InstanceUUID=da6befe867bc4b12-319956a1-4cf14b62-80e8ab78-22dd8c2356ce0c8ca8834383, RequestID=a6e590e0023af35a-7330b281-475149c4-bdbcbf13-f367e5757d875167b1453780, ServiceName=/logging-demo/rest/health/health, InvocationID=8f674cf394dc9e24-823c3722-40a943e5-92d38995-dad45490e14112f95e153ca3, 
 InvokeTimestamp=2018-07-09T0109T14:3748:4501.397Z008Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost	Running /health		ENTRY	
2018-07-09T0109T14:3748:4501.403Z015Z	http-nio-8080-exec-28	INFO	org.onap.demo.logging.ApplicationService	
 ResponseCode=, InstanceUUID=da6befe867bc4b12-319956a1-4cf14b62-80e8ab78-22dd8c2356ce0c8ca8834383, RequestID=a6e590e0023af35a-7330b281-475149c4-bdbcbf13-f367e5757d875167b1453780, ServiceName=/logging-demo/rest/health/health, ResponseDescription=, InvocationID=8f674cf394dc9e24-823c3722-40a943e5-92d38995-dad45490e14112f95e153ca3, Severity=, 
 InvokeTimestamp=2018-07-09T0109T14:3748:4501.397Z008Z, PartnerName=, ClientIPAddress=0:0:0:0:0:0:0:1, ServerFQDN=localhost, StatusCode=			EXIT	


Logging Without Spring AOP

...