From ae22bde4adb459dd142b44c4093e906f545f1cec Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Wed, 11 Apr 2012 01:38:04 -0400 Subject: [PATCH] Supporting jclouds drivers by retrieving the configured logger factory using LoggingModules --- .../demo/tweetstore/config/LoggingConfig.java | 12 +++------- .../config/SpringServletConfig.java | 23 +++++++++++-------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java index de2bf2b913..9852ae59ce 100644 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java +++ b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/LoggingConfig.java @@ -18,9 +18,9 @@ */ package org.jclouds.demo.tweetstore.config; -import org.jclouds.logging.Logger; +import static org.jclouds.logging.LoggingModules.firstOrJDKLoggingModule; + import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.logging.jdk.JDKLogger; /** * Spring config that provides a logger. @@ -28,11 +28,5 @@ import org.jclouds.logging.jdk.JDKLogger; * @author Andrew Phillips */ abstract class LoggingConfig { - private static final LoggerFactory FACTORY = new JDKLogger.JDKLoggerFactory(); - protected final Logger logger; - - protected LoggingConfig() { - logger = FACTORY.getLogger(this.getClass().getName()); - } - + protected static final LoggerFactory LOGGER_FACTORY = firstOrJDKLoggingModule().createLoggerFactory(); } diff --git a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java index 53189d47b3..ba49ded13a 100644 --- a/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java +++ b/demos/tweetstore/gae-tweetstore-spring/src/main/java/org/jclouds/demo/tweetstore/config/SpringServletConfig.java @@ -50,6 +50,7 @@ import org.jclouds.demo.tweetstore.controller.EnqueueStoresController; import org.jclouds.demo.tweetstore.controller.StoreTweetsController; import org.jclouds.demo.tweetstore.functions.ServiceToStoredTweetStatuses; import org.jclouds.gae.config.GoogleAppEngineConfigurationModule; +import org.jclouds.logging.Logger; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -81,6 +82,8 @@ import com.google.inject.Module; public class SpringServletConfig extends LoggingConfig implements ServletConfigAware { public static final String PROPERTY_BLOBSTORE_CONTEXTS = "blobstore.contexts"; + private static final Logger LOGGER = LOGGER_FACTORY.getLogger(SpringServletConfig.class.getName()); + private ServletConfig servletConfig; private Map providerTypeToBlobStoreMap; @@ -93,7 +96,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA BlobStoreContextFactory blobStoreContextFactory = new BlobStoreContextFactory(); Properties props = loadJCloudsProperties(); - logger.trace("About to initialize members."); + LOGGER.trace("About to initialize members."); Module googleModule = new GoogleAppEngineConfigurationModule(); Set modules = ImmutableSet. of(googleModule); @@ -121,7 +124,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA // get a queue for submitting store tweet requests queue = QueueFactory.getQueue("twitter"); - logger.trace("Members initialized. Twitter: '%s', container: '%s', provider types: '%s'", twitterClient, + LOGGER.trace("Members initialized. Twitter: '%s', container: '%s', provider types: '%s'", twitterClient, container, providerTypeToBlobStoreMap.keySet()); } @@ -136,7 +139,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA } private Properties loadJCloudsProperties() { - logger.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties"); + LOGGER.trace("About to read properties from '%s'", "/WEB-INF/jclouds.properties"); Properties props = new Properties(); InputStream input = servletConfig.getServletContext().getResourceAsStream("/WEB-INF/jclouds.properties"); try { @@ -146,7 +149,7 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA } finally { Closeables.closeQuietly(input); } - logger.trace("Properties successfully read."); + LOGGER.trace("Properties successfully read."); return props; } @@ -171,13 +174,13 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA } private void injectServletConfig(Servlet servlet) { - logger.trace("About to inject servlet config '%s'", servletConfig); + LOGGER.trace("About to inject servlet config '%s'", servletConfig); try { servlet.init(checkNotNull(servletConfig)); } catch (ServletException exception) { throw new BeanCreationException("Unable to instantiate " + servlet, exception); } - logger.trace("Successfully injected servlet config."); + LOGGER.trace("Successfully injected servlet config."); } @Bean @@ -208,14 +211,14 @@ public class SpringServletConfig extends LoggingConfig implements ServletConfigA @PreDestroy public void destroy() throws Exception { - logger.trace("About to close contexts."); + LOGGER.trace("About to close contexts."); for (BlobStoreContext context : providerTypeToBlobStoreMap.values()) { context.close(); } - logger.trace("Contexts closed."); - logger.trace("About to purge request queue."); + LOGGER.trace("Contexts closed."); + LOGGER.trace("About to purge request queue."); queue.purge(); - logger.trace("Request queue purged."); + LOGGER.trace("Request queue purged."); } /*