Skip to content

Commit

Permalink
Log lifecycle events in Tomcat and Spring (#376)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Oct 19, 2019
1 parent 0ee797a commit 61674db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Expand Up @@ -28,6 +28,8 @@
*/
package nonapi.io.github.classgraph.classloaderhandler.lifecycle;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

Expand All @@ -52,6 +54,9 @@ public class SpringLifeCycleListener {
ServletListenerRegistrationBean<ServletContextListener> servletListener() {
final ServletListenerRegistrationBean<ServletContextListener> srb = new ServletListenerRegistrationBean<>();
srb.setListener(new ServletContextListener() {
/** The logger. */
private final Logger log = Logger.getLogger(ClassGraph.class.getName());

/**
* Context initialized.
*
Expand All @@ -60,6 +65,7 @@ ServletListenerRegistrationBean<ServletContextListener> servletListener() {
*/
@Override
public void contextInitialized(final ServletContextEvent event) {
log.info("Spring container detected -- disabling ClassGraph shutdown hook");
ClassGraph.disableShutdownHook();
}

Expand All @@ -72,6 +78,7 @@ public void contextInitialized(final ServletContextEvent event) {
@Override
public void contextDestroyed(final ServletContextEvent event) {
// Cleanly close down any open {@link ScanResult} instances.
log.info("Closing any remaning open ClassGraph ScanResult instances");
ScanResult.closeAll();
}
});
Expand Down
Expand Up @@ -28,6 +28,8 @@
*/
package nonapi.io.github.classgraph.classloaderhandler.lifecycle;

import java.util.logging.Logger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
Expand All @@ -45,6 +47,9 @@
*/
@WebListener
public class TomcatLifeCycleListener implements ServletContextListener {
/** The logger. */
private final Logger log = Logger.getLogger(ClassGraph.class.getName());

/**
* Context initialized.
*
Expand All @@ -53,6 +58,7 @@ public class TomcatLifeCycleListener implements ServletContextListener {
*/
@Override
public void contextInitialized(final ServletContextEvent event) {
log.info("Tomcat container detected -- disabling ClassGraph shutdown hook");
ClassGraph.disableShutdownHook();
}

Expand All @@ -65,6 +71,7 @@ public void contextInitialized(final ServletContextEvent event) {
@Override
public void contextDestroyed(final ServletContextEvent event) {
// Cleanly close down any open {@link ScanResult} instances.
log.info("Closing any remaning open ClassGraph ScanResult instances");
ScanResult.closeAll();
}
}
3 changes: 1 addition & 2 deletions src/main/java/nonapi/io/github/classgraph/utils/LogNode.java
Expand Up @@ -49,8 +49,7 @@
* retain a sane order. The order may also be made deterministic by specifying a sort key for log entries.
*/
public final class LogNode {

/** The Constant log. */
/** The logger. */
private static final Logger log = Logger.getLogger(ClassGraph.class.getName());

/**
Expand Down

0 comments on commit 61674db

Please sign in to comment.