From 9ea2654514ec87e08ec787d2f60e3e8ff4000620 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 17 Jun 2016 16:34:57 -0700 Subject: [PATCH] Issue #231 - Reworking logging for slfj4 + logback + Logging rollover is based on individual file size and rollover count + Checkstyle updates + Better testing --- .../apphosting/logging/JsonLayoutTest.java | 2 - .../vmruntime/VmRuntimeLogging.java | 15 +- .../src/main/jetty-base/resources/logback.xml | 11 +- jetty9-compat-base/pom.xml | 17 +- .../jetty9/VmRuntimeWebAppContext.java | 163 ++++++++---------- .../src/main/jetty-base/resources/logback.xml | 11 +- .../vmruntime/jetty9/IntegrationEnv.java | 27 +++ .../vmruntime/jetty9/JettyRunner.java | 47 ++--- .../vmruntime/jetty9/VmRuntimeTestBase.java | 17 +- .../test/resources/jetty-logging.properties | 6 +- .../src/test/resources/logback.xml | 33 ++++ .../test/resources/webapp/WEB-INF/logback.xml | 15 ++ .../webapp/WEB-INF/logging.properties | 30 ---- .../src/main/webapp/WEB-INF/logback.xml | 8 + .../main/webapp/WEB-INF/logging.properties | 36 ---- 15 files changed, 208 insertions(+), 230 deletions(-) create mode 100644 jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/IntegrationEnv.java create mode 100644 jetty9-compat-base/src/test/resources/logback.xml create mode 100644 jetty9-compat-base/src/test/resources/webapp/WEB-INF/logback.xml delete mode 100644 jetty9-compat-base/src/test/resources/webapp/WEB-INF/logging.properties create mode 100644 testwebapp/src/main/webapp/WEB-INF/logback.xml delete mode 100644 testwebapp/src/main/webapp/WEB-INF/logging.properties diff --git a/appengine-java-logging/src/test/java/com/google/apphosting/logging/JsonLayoutTest.java b/appengine-java-logging/src/test/java/com/google/apphosting/logging/JsonLayoutTest.java index 6dcc237..48c27e6 100644 --- a/appengine-java-logging/src/test/java/com/google/apphosting/logging/JsonLayoutTest.java +++ b/appengine-java-logging/src/test/java/com/google/apphosting/logging/JsonLayoutTest.java @@ -168,7 +168,6 @@ public void testCommonsLogging() { if (data.severity.equals("ERROR")) { assertThat("throwable", data.throwable, startsWith("java.lang.RuntimeException: Generic Error")); - } } } @@ -280,7 +279,6 @@ public static class LogTimestamp { public int nanos; } - public LogTimestamp timestamp; public String severity; public String thread; diff --git a/appengine-managed-runtime/src/main/java/com/google/apphosting/vmruntime/VmRuntimeLogging.java b/appengine-managed-runtime/src/main/java/com/google/apphosting/vmruntime/VmRuntimeLogging.java index b09dbc3..213b16e 100644 --- a/appengine-managed-runtime/src/main/java/com/google/apphosting/vmruntime/VmRuntimeLogging.java +++ b/appengine-managed-runtime/src/main/java/com/google/apphosting/vmruntime/VmRuntimeLogging.java @@ -41,27 +41,30 @@ public static void load(String logbackXmlFile) throws AppEngineConfigException { LoggerContext rootContext = (LoggerContext) StaticLoggerBinder.getSingleton().getLoggerFactory(); - // Load user provided logback XML + // Reset root + rootContext.reset(); + + // Load user provided logback XML (aka the User Configuration) ContextInitializer initializer = new ContextInitializer(rootContext); if ((logbackXmlFile != null) && (logbackXmlFile.length() > 0)) { System.setProperty(LOGGING_CONFIGURATION_KEY, logbackXmlFile); try { initializer.autoConfig(); + System.err.println("## Initialized User Logging from " + logbackXmlFile); } catch (JoranException e) { throw new AppEngineConfigException(e); } } - // Load the system logback XML + // Load the system logback XML (aka the System Configuration) try { Enumeration configUrls = - VmRuntimeLogging.class.getClass().getClassLoader().getResources("logback.xml"); + VmRuntimeLogging.class.getClassLoader().getResources("logback.xml"); while (configUrls.hasMoreElements()) { URL url = configUrls.nextElement(); - if (url.toExternalForm().endsWith("resources/logback.xml")) { - initializer.configureByResource(url); - } + System.err.println("## Initialized System Logging from " + url); + initializer.configureByResource(url); } } catch (JoranException | IOException e) { throw new AppEngineConfigException(e); diff --git a/jetty9-base/src/main/jetty-base/resources/logback.xml b/jetty9-base/src/main/jetty-base/resources/logback.xml index ef721be..03a2467 100644 --- a/jetty9-base/src/main/jetty-base/resources/logback.xml +++ b/jetty9-base/src/main/jetty-base/resources/logback.xml @@ -7,12 +7,15 @@ /var/log/app_engine/app.%i.log.json - + + app.%i.log.json - 30 + 1 + 10 - - + + 5MB + diff --git a/jetty9-compat-base/pom.xml b/jetty9-compat-base/pom.xml index 3aa4808..bbce18b 100644 --- a/jetty9-compat-base/pom.xml +++ b/jetty9-compat-base/pom.xml @@ -77,20 +77,9 @@ - junit - junit - test - - - org.hamcrest - hamcrest-library - 1.3 - test - - - org.hamcrest - hamcrest-core - 1.3 + org.eclipse.jetty.toolchain + jetty-test-helper + 4.0 test diff --git a/jetty9-compat-base/src/main/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeWebAppContext.java b/jetty9-compat-base/src/main/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeWebAppContext.java index cc027f4..2fadddf 100644 --- a/jetty9-compat-base/src/main/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeWebAppContext.java +++ b/jetty9-compat-base/src/main/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeWebAppContext.java @@ -43,6 +43,7 @@ import com.google.apphosting.vmruntime.VmRuntimeLogging; import com.google.apphosting.vmruntime.VmRuntimeUtils; import com.google.apphosting.vmruntime.VmTimer; + import org.eclipse.jetty.quickstart.PreconfigureDescriptorProcessor; import org.eclipse.jetty.quickstart.QuickStartDescriptorGenerator; import org.eclipse.jetty.security.ConstraintSecurityHandler; @@ -83,14 +84,10 @@ public class VmRuntimeWebAppContext extends WebAppContext // It's undesirable to have the user app override classes provided by us. // So we mark them as Jetty system classes, which cannot be overridden. private static final String[] SYSTEM_CLASSES = { - // The trailing dot means these are all Java packages, not individual classes. - "com.google.appengine.api.", - "com.google.appengine.tools.", - "com.google.apphosting.", - "com.google.cloud.sql.jdbc.", - "com.google.protos.cloud.sql.", - "com.google.storage.onestore.", - }; + // The trailing dot means these are all Java packages, not individual classes. + "com.google.appengine.api.", "com.google.appengine.tools.", "com.google.apphosting.", + "com.google.cloud.sql.jdbc.", "com.google.protos.cloud.sql.", + "com.google.storage.onestore.",}; // constant. If it's much larger than this we may need to // restructure the code a bit. protected static final int MAX_RESPONSE_SIZE = 32 * 1024 * 1024; @@ -108,34 +105,32 @@ public class VmRuntimeWebAppContext extends WebAppContext static { // Set SPI classloader priority to prefer the WebAppClassloader. - System.setProperty( - ServiceFactoryFactory.USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY, Boolean.TRUE.toString()); + System.setProperty(ServiceFactoryFactory.USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY, + Boolean.TRUE.toString()); // Use thread context class loader for memcache deserialization. - System.setProperty( - MemcacheSerialization.USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY, Boolean.TRUE.toString()); + System.setProperty(MemcacheSerialization.USE_THREAD_CONTEXT_CLASSLOADER_PROPERTY, + Boolean.TRUE.toString()); } // List of Jetty configuration only needed if the quickstart process has been // executed, so we do not need the webinf, wedxml, fragment and annotation configurations // because they have been executed via the SDK. - private static final String[] quickstartConfigurationClasses = { - org.eclipse.jetty.quickstart.QuickStartConfiguration.class.getCanonicalName(), - org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), - org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), - org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName() - }; + private static final String[] quickstartConfigurationClasses = + {org.eclipse.jetty.quickstart.QuickStartConfiguration.class.getCanonicalName(), + org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), + org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), + org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName()}; // List of all the standard Jetty configurations that need to be executed when there // is no quickstart-web.xml. - private static final String[] preconfigurationClasses = { - org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(), - org.eclipse.jetty.webapp.WebXmlConfiguration.class.getCanonicalName(), - org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(), - org.eclipse.jetty.webapp.FragmentConfiguration.class.getCanonicalName(), - org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), - org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), - org.eclipse.jetty.annotations.AnnotationConfiguration.class.getCanonicalName() - }; + private static final String[] preconfigurationClasses = + {org.eclipse.jetty.webapp.WebInfConfiguration.class.getCanonicalName(), + org.eclipse.jetty.webapp.WebXmlConfiguration.class.getCanonicalName(), + org.eclipse.jetty.webapp.MetaInfConfiguration.class.getCanonicalName(), + org.eclipse.jetty.webapp.FragmentConfiguration.class.getCanonicalName(), + org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(), + org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(), + org.eclipse.jetty.annotations.AnnotationConfiguration.class.getCanonicalName()}; public String getQuickstartWebXml() { return quickstartWebXml; @@ -147,7 +142,7 @@ public VmMetadataCache getMetadataCache() { /** * Set the quickstart WebXml. - * + *

*

If set, this context will not start, rather it will generate the * quickstart-web.xml file and then stop the server. If not set, the context will start normally *

@@ -237,11 +232,10 @@ DatastoreService getDatastoreService() { * @return A List of SessionStores in write order. */ private static List createSessionStores(AppEngineWebXml appEngineWebXml) { - DatastoreSessionStore datastoreSessionStore = - appEngineWebXml.getAsyncSessionPersistence() - ? new DeferredDatastoreSessionStore( - appEngineWebXml.getAsyncSessionPersistenceQueueName()) - : new DatastoreSessionStore(); + DatastoreSessionStore datastoreSessionStore = appEngineWebXml.getAsyncSessionPersistence() + ? new DeferredDatastoreSessionStore( + appEngineWebXml.getAsyncSessionPersistenceQueueName()) + : new DatastoreSessionStore(); // Write session data to the datastore before we write to memcache. return Arrays.asList(datastoreSessionStore, new MemcacheSessionStore()); } @@ -255,8 +249,8 @@ public VmRuntimeWebAppContext() { // Configure the Jetty SecurityHandler to understand our method of authentication // (via the UserService). Only the default ConstraintSecurityHandler is supported. - AppEngineAuthentication.configureSecurityHandler( - (ConstraintSecurityHandler) getSecurityHandler(), this); + AppEngineAuthentication + .configureSecurityHandler((ConstraintSecurityHandler) getSecurityHandler(), this); setMaxFormContentSize(MAX_RESPONSE_SIZE); setConfigurationClasses(preconfigurationClasses); @@ -271,7 +265,7 @@ public VmRuntimeWebAppContext() { /** * Initialize the WebAppContext for use by the VmRuntime. - * + *

*

* This method initializes the WebAppContext by setting the context path and * application folder. It will also parse the appengine-web.xml file provided to @@ -280,19 +274,14 @@ public VmRuntimeWebAppContext() { * * @param appengineWebXmlFile The appengine-web.xml file path (relative to appDir). * @throws AppEngineConfigException If there was a problem finding or parsing the - * appengine-web.xml configuration. - * @throws IOException If the runtime was unable to find/read appDir. + * appengine-web.xml configuration. + * @throws IOException If the runtime was unable to find/read appDir. */ public void init(String appengineWebXmlFile) throws AppEngineConfigException, IOException { String appDir = getBaseResource().getFile().getCanonicalPath(); - defaultEnvironment = - VmApiProxyEnvironment.createDefaultContext( - System.getenv(), - metadataCache, - VmRuntimeUtils.getApiServerAddress(), - wallclockTimer, - VmRuntimeUtils.ONE_DAY_IN_MILLIS, - appDir); + defaultEnvironment = VmApiProxyEnvironment + .createDefaultContext(System.getenv(), metadataCache, VmRuntimeUtils.getApiServerAddress(), + wallclockTimer, VmRuntimeUtils.ONE_DAY_IN_MILLIS, appDir); ApiProxy.setEnvironmentForCurrentThread(defaultEnvironment); if (ApiProxy.getEnvironmentFactory() == null) { // Need the check above since certain unit tests initialize the context multiple times. @@ -364,15 +353,10 @@ class RequestContext extends HttpServletRequestAdapter { RequestContext(Request request) { super(request); - requestSpecificEnvironment = - VmApiProxyEnvironment.createFromHeaders( - System.getenv(), - metadataCache, - this, - VmRuntimeUtils.getApiServerAddress(), - wallclockTimer, - VmRuntimeUtils.ONE_DAY_IN_MILLIS, - defaultEnvironment); + requestSpecificEnvironment = VmApiProxyEnvironment + .createFromHeaders(System.getenv(), metadataCache, this, + VmRuntimeUtils.getApiServerAddress(), wallclockTimer, + VmRuntimeUtils.ONE_DAY_IN_MILLIS, defaultEnvironment); if (requestSpecificEnvironment.isRequestTicket()) { final HttpOutput httpOutput = request.getResponse().getHttpOutput(); final HttpOutput.Interceptor nextOutput = httpOutput.getInterceptor(); @@ -386,21 +370,17 @@ VmApiProxyEnvironment getRequestSpecificEnvironment() { @Override public String toString() { - return String.format( - "RequestContext@%x %s==%s", - hashCode(), - request.getRequestURI(), + return String.format("RequestContext@%x %s==%s", hashCode(), request.getRequestURI(), requestSpecificEnvironment); } } + public class ContextListener implements ContextHandler.ContextScopeListener, ServletRequestListener { @Override - public void enterScope( - org.eclipse.jetty.server.handler.ContextHandler.Context context, - Request baseRequest, - Object reason) { + public void enterScope(org.eclipse.jetty.server.handler.ContextHandler.Context context, + Request baseRequest, Object reason) { RequestContext requestContext = getRequestContext(baseRequest); if (requestContext == null) { logger.fine("enterScope no request"); @@ -439,32 +419,32 @@ public void requestDestroyed(ServletRequestEvent sre) { logger.fine("requestDestroyed " + getRequestContext(baseRequest)); } if (request.isAsyncStarted()) { - request - .getAsyncContext() - .addListener( - new AsyncListener() { - @Override - public void onTimeout(AsyncEvent event) throws IOException {} - - @Override - public void onStartAsync(AsyncEvent event) throws IOException {} - - @Override - public void onError(AsyncEvent event) throws IOException {} - - @Override - public void onComplete(AsyncEvent event) throws IOException { - complete(baseRequest); - } - }); + request.getAsyncContext().addListener(new AsyncListener() { + @Override + public void onTimeout(AsyncEvent event) throws IOException { + } + + @Override + public void onStartAsync(AsyncEvent event) throws IOException { + } + + @Override + public void onError(AsyncEvent event) throws IOException { + } + + @Override + public void onComplete(AsyncEvent event) throws IOException { + complete(baseRequest); + } + }); } else { complete(baseRequest); } } @Override - public void exitScope( - org.eclipse.jetty.server.handler.ContextHandler.Context context, Request baseRequest) { + public void exitScope(org.eclipse.jetty.server.handler.ContextHandler.Context context, + Request baseRequest) { if (logger.isLoggable(Level.FINE)) { if (baseRequest == null) { logger.fine("exitScope"); @@ -499,8 +479,8 @@ private void complete(Request baseRequest) { } // Interrupt all API calls - VmRuntimeUtils.interruptRequestThreads( - env, VmRuntimeUtils.MAX_REQUEST_THREAD_INTERRUPT_WAIT_TIME_MS); + VmRuntimeUtils + .interruptRequestThreads(env, VmRuntimeUtils.MAX_REQUEST_THREAD_INTERRUPT_WAIT_TIME_MS); env.waitForAllApiCallsToComplete(VmRuntimeUtils.MAX_REQUEST_THREAD_API_CALL_WAIT_MS); } @@ -510,19 +490,14 @@ void handleAbandonedTxns(Collection txns) { for (Transaction txn : txns) { try { logger.warning( - "Request completed without committing or rolling back transaction with id " - + txn.getId() - + ". Transaction will be rolled back."); + "Request completed without committing or rolling back transaction with id " + txn + .getId() + ". Transaction will be rolled back."); txn.rollback(); } catch (Exception e) { // We swallow exceptions so that there is no risk of our cleanup // impacting the actual result of the request. - logger.log( - Level.WARNING, - "Swallowing an exception we received while trying to rollback " - + "abandoned transaction with id " - + txn.getId(), - e); + logger.log(Level.WARNING, "Swallowing an exception we received while trying to rollback " + + "abandoned transaction with id " + txn.getId(), e); } } } diff --git a/jetty9-compat-base/src/main/jetty-base/resources/logback.xml b/jetty9-compat-base/src/main/jetty-base/resources/logback.xml index ef721be..03a2467 100644 --- a/jetty9-compat-base/src/main/jetty-base/resources/logback.xml +++ b/jetty9-compat-base/src/main/jetty-base/resources/logback.xml @@ -7,12 +7,15 @@ /var/log/app_engine/app.%i.log.json - + + app.%i.log.json - 30 + 1 + 10 - - + + 5MB + diff --git a/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/IntegrationEnv.java b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/IntegrationEnv.java new file mode 100644 index 0000000..066c4fe --- /dev/null +++ b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/IntegrationEnv.java @@ -0,0 +1,27 @@ +package com.google.apphosting.vmruntime.jetty9; + +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.PathAssert; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; + +/** + * Environment for IT tests. + *

+ * Specifically designed to establish environment for IT tests without initializing anything + * that the IT test cases need (such as System Properties and/or Logging) + *

+ */ +public class IntegrationEnv { + public static Path getJettyBase() throws IOException { + Path jettyBase = MavenTestingUtils.getTargetPath("jetty-base"); + if (System.getProperty("jetty.base") != null) { + jettyBase = new File(System.getProperty("jetty.base")).toPath().toRealPath(); + } + + PathAssert.assertDirExists("jetty.base", jettyBase); + return jettyBase; + } +} diff --git a/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/JettyRunner.java b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/JettyRunner.java index 3f8541c..08f055c 100644 --- a/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/JettyRunner.java +++ b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/JettyRunner.java @@ -16,11 +16,10 @@ package com.google.apphosting.vmruntime.jetty9; -import static com.google.apphosting.vmruntime.VmRuntimeFileLogHandler.JAVA_UTIL_LOGGING_CONFIG_PROPERTY; import static com.google.apphosting.vmruntime.jetty9.VmRuntimeTestBase.JETTY_HOME_PATTERN; import com.google.apphosting.jetty9.GoogleRequestCustomizer; -import com.google.apphosting.vmruntime.VmRuntimeFileLogHandler; +import com.google.apphosting.vmruntime.VmRuntimeLogging; import org.eclipse.jetty.apache.jsp.JettyJasperInitializer; import org.eclipse.jetty.io.MappedByteBufferPool; @@ -35,6 +34,8 @@ import org.eclipse.jetty.server.handler.DefaultHandler; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.RequestLogHandler; +import org.eclipse.jetty.toolchain.test.MavenTestingUtils; +import org.eclipse.jetty.toolchain.test.PathAssert; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -43,6 +44,7 @@ import java.io.File; import java.io.IOException; import java.net.ServerSocket; +import java.nio.file.Path; import java.util.Collections; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; @@ -106,29 +108,13 @@ public void waitForStarted(long timeout, TimeUnit units) throws InterruptedExcep @Override public void doStart() throws Exception { try { - // find projectDir - File project = - new File(System.getProperty("user.dir", ".")).getAbsoluteFile().getCanonicalFile(); - File target = new File(project, "jetty9-compat-base/target"); - while (!target.exists()) { - project = project.getParentFile(); - if (project == null) { - break; - } - target = new File(project, "jetty9-compat-base/target"); + Path jettyBase = IntegrationEnv.getJettyBase(); + logs = jettyBase.resolve("logs").toFile(); + if (logs.exists()) { + logs.delete(); + logs.mkdirs(); } - File jettyBase = - new File( - System.getProperty("jetty.base", new File(target, "jetty-base").getAbsolutePath())); - - Assert.assertTrue(target.isDirectory()); - Assert.assertTrue(jettyBase.isDirectory()); - logs = new File(target, "logs"); - logs.delete(); - logs.mkdirs(); - logs.deleteOnExit(); - // Set GAE SystemProperties setSystemProperties(logs); @@ -209,13 +195,12 @@ public void doStart() throws Exception { true); // find the sibling testwebapp target - File webAppLocation = new File(target, webapp); + File webAppLocation = MavenTestingUtils.getTargetFile(webapp); + PathAssert.assertDirExists("webapp dir", webAppLocation); - File logging = - new File(webAppLocation, "WEB-INF/logging.properties") - .getCanonicalFile() - .getAbsoluteFile(); - System.setProperty(JAVA_UTIL_LOGGING_CONFIG_PROPERTY, logging.toPath().toString()); + Path logging = webAppLocation.toPath().resolve("WEB-INF/logback.xml"); + System.setProperty( + VmRuntimeLogging.LOGGING_CONFIGURATION_KEY, logging.toRealPath().toString()); Assert.assertTrue(webAppLocation.toString(), webAppLocation.isDirectory()); @@ -224,7 +209,7 @@ public void doStart() throws Exception { context.setParentLoaderPriority(true); // true in tests for easier mocking // Hack to find the webdefault.xml - File webDefault = new File(jettyBase, "etc/webdefault.xml"); + File webDefault = jettyBase.resolve("etc/webdefault.xml").toFile(); context.setDefaultsDescriptor(webDefault.getAbsolutePath()); contexts.addHandler(context); @@ -258,8 +243,6 @@ public void run() { * Sets the system properties expected by jetty.xml. */ protected void setSystemProperties(File logs) throws IOException { - String logFilePattern = logs.getAbsolutePath() + "/log.%g"; - System.setProperty(VmRuntimeFileLogHandler.LOG_PATTERN_CONFIG_PROPERTY, logFilePattern); System.setProperty("jetty.appengineport", String.valueOf(findAvailablePort())); System.setProperty("jetty.appenginehost", "localhost"); System.setProperty("jetty.appengine.forwarded", "true"); diff --git a/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java index bcafcc7..7bd637b 100644 --- a/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java +++ b/jetty9-compat-base/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java @@ -20,7 +20,6 @@ import static com.google.apphosting.vmruntime.VmMetadataCache.META_DATA_PATTERN; import junit.framework.TestCase; - import org.junit.Ignore; import java.io.BufferedReader; @@ -31,6 +30,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -45,7 +45,18 @@ @Ignore public class VmRuntimeTestBase extends TestCase { - protected static final Logger logger = Logger.getLogger(VmRuntimeTestBase.class.getName()); + static { + try { + Path jettyBase = IntegrationEnv.getJettyBase(); + System.setProperty("jetty.base", jettyBase.toString()); + } catch (IOException e) { + e.printStackTrace(); + } + + LOG = Logger.getLogger(VmRuntimeTestBase.class.getName()); + } + + protected static final Logger LOG; private static final String HOME_FOLDER = System.getProperty("HOME_FOLDER", "jetty_home"); public static final String JETTY_HOME_PATTERN = "" //TestUtil.getRunfilesDir() @@ -197,7 +208,7 @@ protected String getMetadataFromServer(String path) throws IOException { try { reader.close(); } catch (IOException e) { - logger.info("Error closing connection for " + path + ": " + e.getMessage()); + LOG.info("Error closing connection for " + path + ": " + e.getMessage()); } } if (connection != null) { diff --git a/jetty9-compat-base/src/test/resources/jetty-logging.properties b/jetty9-compat-base/src/test/resources/jetty-logging.properties index aa44873..7f720bb 100644 --- a/jetty9-compat-base/src/test/resources/jetty-logging.properties +++ b/jetty9-compat-base/src/test/resources/jetty-logging.properties @@ -14,8 +14,4 @@ # limitations under the License. # -#org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.JavaUtilLog -org.eclipse.jetty.LEVEL=INFO -org.eclipse.jetty.webapp.LEVEL=INFO -org.eclipse.jetty.servlet.LEVEL=INFO +org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4jLog diff --git a/jetty9-compat-base/src/test/resources/logback.xml b/jetty9-compat-base/src/test/resources/logback.xml new file mode 100644 index 0000000..21f3700 --- /dev/null +++ b/jetty9-compat-base/src/test/resources/logback.xml @@ -0,0 +1,33 @@ + + + + + true + + + + target/jetty-base/logs/app.0.log.json + + + app.%i.log.json + 1 + 10 + + + 5MB + + + + + target/jetty-base/logs/app.0.log + true + + %-4relative [%thread] %-5level %logger{35} - %msg %n + + + + + + + + diff --git a/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logback.xml b/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logback.xml new file mode 100644 index 0000000..9759191 --- /dev/null +++ b/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logback.xml @@ -0,0 +1,15 @@ + + + + + %-4relative [%thread] %-5level %logger{35} - %msg %n + + + + + + + + + + diff --git a/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logging.properties b/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logging.properties deleted file mode 100644 index 204a16a..0000000 --- a/jetty9-compat-base/src/test/resources/webapp/WEB-INF/logging.properties +++ /dev/null @@ -1,30 +0,0 @@ - -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# Console Logging -handlers = java.util.logging.ConsoleHandler -java.util.logging.ConsoleHandler.level = ALL - -# Set the default logging level for all loggers to INFO -.level=INFO - -# Override root level -com.foo.level=FINE - -# Override parent's level -com.foo.bar.level=SEVERE - diff --git a/testwebapp/src/main/webapp/WEB-INF/logback.xml b/testwebapp/src/main/webapp/WEB-INF/logback.xml new file mode 100644 index 0000000..4401df7 --- /dev/null +++ b/testwebapp/src/main/webapp/WEB-INF/logback.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/testwebapp/src/main/webapp/WEB-INF/logging.properties b/testwebapp/src/main/webapp/WEB-INF/logging.properties deleted file mode 100644 index b21b38f..0000000 --- a/testwebapp/src/main/webapp/WEB-INF/logging.properties +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# A default java.util.logging configuration. -# (All App Engine logging is through java.util.logging by default). -# -# To use this configuration, copy it into your application's WEB-INF -# folder and add the following to your appengine-web.xml: -# -# -# -# -# - -# Set the default logging level for all loggers to INFO -.level=INFO - -# Override root level -com.foo.level=FINE - -# Override parent's level -com.foo.bar.level=SEVERE -