diff --git a/community/server/src/main/java/org/neo4j/server/AbstractNeoServer.java b/community/server/src/main/java/org/neo4j/server/AbstractNeoServer.java index b6c33c93e1563..97a058afd468c 100644 --- a/community/server/src/main/java/org/neo4j/server/AbstractNeoServer.java +++ b/community/server/src/main/java/org/neo4j/server/AbstractNeoServer.java @@ -92,7 +92,6 @@ import static org.neo4j.helpers.collection.Iterables.map; import static org.neo4j.kernel.impl.util.JobScheduler.Groups.serverTransactionTimeout; import static org.neo4j.server.configuration.ServerSettings.httpConnector; -import static org.neo4j.server.configuration.ServerSettings.http_log_config_file; import static org.neo4j.server.configuration.ServerSettings.http_logging_enabled; import static org.neo4j.server.database.InjectableProvider.providerForSingleton; import static org.neo4j.server.exception.ServerStartupErrors.translateToServerStartupError; @@ -325,12 +324,16 @@ private void startWebServer() throws Exception private void setUpHttpLogging() { - if ( !httpLoggingProperlyConfigured() ) + if ( !getConfig().get( http_logging_enabled ) ) { return; } - webServer.setHttpLoggingConfiguration(config.get( http_log_config_file ), config.get( http_logging_enabled )); + System.out.println("HELLO THERE"); + System.out.println(config.get( GraphDatabaseSettings.logs_directory ).toString() ); + + webServer.setHttpLoggingConfiguration(config.get( GraphDatabaseSettings.logs_directory ), + config.get( http_logging_enabled ) ); } private void setUpTimeoutFilter() @@ -352,22 +355,6 @@ private void setUpTimeoutFilter() webServer.addFilter( filter, "/*" ); } - private boolean httpLoggingProperlyConfigured() - { - return loggingEnabled() && configLocated(); - } - - private boolean configLocated() - { - final File logFile = getConfig().get( http_log_config_file ); - return logFile != null && logFile.exists(); - } - - private boolean loggingEnabled() - { - return getConfig().get( http_logging_enabled ); - } - public HostnamePort getAddress() { return httpAddress; diff --git a/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java b/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java index 7fb91c2e63a9f..b0331f027e9e5 100644 --- a/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java +++ b/community/server/src/main/java/org/neo4j/server/configuration/ServerSettings.java @@ -173,14 +173,6 @@ private ThirdPartyJaxRsPackage createThirdPartyJaxRsPackage( String packageAndMo @Description("Enable HTTP request logging.") Setting http_logging_enabled = setting( "org.neo4j.server.http.log.enabled", BOOLEAN, FALSE ); - @Description("Enable HTTP content logging.") - Setting http_content_logging_enabled = setting( "org.neo4j.server.http.unsafe.content_log.enabled", - BOOLEAN, FALSE ); - - @Description("Path to a logback configuration file for HTTP request logging.") - Setting http_log_config_file = setting( "org.neo4j.server.http.log.config", new HttpLogSetting(), - NO_DEFAULT ); - @SuppressWarnings("unused") // used only in the startup scripts @Description("Enable GC Logging") Setting gc_logging_enabled = setting("dbms.logs.gc.enabled", BOOLEAN, FALSE); diff --git a/community/server/src/main/java/org/neo4j/server/preflight/EnsurePreparedForHttpLogging.java b/community/server/src/main/java/org/neo4j/server/preflight/EnsurePreparedForHttpLogging.java deleted file mode 100644 index 414415b94e987..0000000000000 --- a/community/server/src/main/java/org/neo4j/server/preflight/EnsurePreparedForHttpLogging.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.server.preflight; - -import org.apache.commons.io.FileUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import java.io.File; -import java.io.IOException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; - -import org.neo4j.kernel.configuration.Config; -import org.neo4j.server.configuration.ServerSettings; - -public class EnsurePreparedForHttpLogging implements PreflightTask -{ - private String failureMessage = ""; - private Config config; - - public EnsurePreparedForHttpLogging( Config config ) - { - this.config = config; - } - - @Override - public boolean run() - { - boolean enabled = config.get( ServerSettings.http_logging_enabled ); - if ( !enabled ) - { - return true; - } - - File configFile = config.get( ServerSettings.http_log_config_file ); - if ( configFile == null ) - { - failureMessage = "HTTP logging configuration file is not specified"; - return false; - } - - File logLocation = extractLogLocationFromConfig( configFile.getAbsolutePath() ); - if ( logLocation != null ) - { - return validateFileBasedLoggingConfig( logLocation ); - } - // File logging is not configured, no other logging can be easily checked here - return true; - } - - private boolean validateFileBasedLoggingConfig( File logLocation ) - { - try - { - FileUtils.forceMkdir( logLocation ); - } - catch ( IOException e ) - { - failureMessage = String.format( "HTTP log directory [%s] does not exist", - logLocation.getAbsolutePath() ); - return false; - } - - if ( !logLocation.exists() ) - { - failureMessage = String.format( "HTTP log directory [%s] cannot be created", - logLocation.getAbsolutePath() ); - return false; - } - - if ( !logLocation.canWrite() ) - { - failureMessage = String.format( "HTTP log directory [%s] is not writable", - logLocation.getAbsolutePath() ); - return false; - } - - return true; - } - - private File extractLogLocationFromConfig( String configLocation ) - { - DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); - try - { - final File file = new File( configLocation ); - - DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); - Document doc = docBuilder.parse( file ); - - final Node node = doc.getElementsByTagName( "file" ).item( 0 ); - - return new File( node.getTextContent() ).getParentFile(); - } - catch ( Exception e ) - { - return null; - } - } - - @Override - public String getFailureMessage() - { - return failureMessage; - } -} diff --git a/community/server/src/main/java/org/neo4j/server/web/AsyncRequestLog.java b/community/server/src/main/java/org/neo4j/server/web/AsyncRequestLog.java index 23760842d57de..65177a27fe5c6 100644 --- a/community/server/src/main/java/org/neo4j/server/web/AsyncRequestLog.java +++ b/community/server/src/main/java/org/neo4j/server/web/AsyncRequestLog.java @@ -24,9 +24,7 @@ import org.eclipse.jetty.server.Response; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; +import java.io.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; @@ -52,7 +50,6 @@ public class AsyncRequestLog public AsyncRequestLog( FileSystemAbstraction fs, String logFile ) throws IOException { - System.out.println( "logFile = " + logFile ); NamedThreadFactory threadFactory = new NamedThreadFactory( "HTTP-Log-Rotator", true ); ExecutorService rotationExecutor = Executors.newCachedThreadPool( threadFactory ); Supplier outputSupplier = new RotatingFileOutputStreamSupplier( @@ -79,6 +76,7 @@ public void log( Request request, Response response ) long requestTimeStamp = request.getTimeStamp(); long now = System.currentTimeMillis(); long serviceTime = requestTimeStamp < 0 ? -1 : now - requestTimeStamp; + log.info( "%s - %s [%tc] \"%s\" %s %s \"%s\" \"%s\" %s", remoteHost, user, now, requestURL, statusCode, length, referer, userAgent, serviceTime ); } diff --git a/community/server/src/main/java/org/neo4j/server/web/Jetty9WebServer.java b/community/server/src/main/java/org/neo4j/server/web/Jetty9WebServer.java index 711b4374124ba..cc434e88c0b9b 100644 --- a/community/server/src/main/java/org/neo4j/server/web/Jetty9WebServer.java +++ b/community/server/src/main/java/org/neo4j/server/web/Jetty9WebServer.java @@ -25,16 +25,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.*; import java.util.concurrent.BlockingQueue; import java.util.function.Consumer; import javax.servlet.DispatcherType; @@ -130,7 +121,7 @@ public String getPathSpec() private KeyStoreInformation httpsCertificateInformation = null; private final SslSocketConnectorFactory sslSocketFactory; private final HttpConnectorFactory connectorFactory; - private File requestLoggingConfiguration; + private File requestLogFile; private final Log log; public Jetty9WebServer( LogProvider logProvider, Config config ) @@ -331,12 +322,11 @@ public void invokeDirectly( String targetPath, HttpServletRequest request, HttpS } @Override - public void setHttpLoggingConfiguration( File logbackConfigFile, boolean enableContentLogging ) + public void setHttpLoggingConfiguration( File logsDirectory, boolean enableLogging ) { - this.requestLoggingConfiguration = logbackConfigFile; - if(enableContentLogging) + if( enableLogging ) { - addFilter( new TeeFilter(), "/*" ); + this.requestLogFile = new File( logsDirectory, "http.log" ); } } @@ -408,7 +398,7 @@ else if ( isJaxrsClass ) } } - if ( requestLoggingConfiguration != null ) + if ( requestLogFile != null ) { loadRequestLogging(); } @@ -431,7 +421,7 @@ private void loadRequestLogging() throws IOException { RequestLog requestLog = new AsyncRequestLog( new DefaultFileSystemAbstraction(), - requestLoggingConfiguration.getAbsolutePath() ); + requestLogFile.getAbsolutePath() ); // This makes the request log handler decorate whatever other handlers are already set up final RequestLogHandler requestLogHandler = new RequestLogHandler(); diff --git a/community/server/src/main/java/org/neo4j/server/web/WebServer.java b/community/server/src/main/java/org/neo4j/server/web/WebServer.java index 6afacc2f70746..21d9523c4a1f5 100644 --- a/community/server/src/main/java/org/neo4j/server/web/WebServer.java +++ b/community/server/src/main/java/org/neo4j/server/web/WebServer.java @@ -45,7 +45,7 @@ public interface WebServer void setHttpsCertificateInformation( KeyStoreInformation config ); - void setHttpLoggingConfiguration( File logbackConfig, boolean enableContentLogging ); + void setHttpLoggingConfiguration( File logbackConfig, boolean enableLogging ); void setMaxThreads( int maxThreads ); diff --git a/community/server/src/test/java/org/neo4j/server/ServerTestUtils.java b/community/server/src/test/java/org/neo4j/server/ServerTestUtils.java index 049c57ac190b3..84b60a720575a 100644 --- a/community/server/src/test/java/org/neo4j/server/ServerTestUtils.java +++ b/community/server/src/test/java/org/neo4j/server/ServerTestUtils.java @@ -65,20 +65,6 @@ public static File createTempConfigFile() throws IOException return file; } - public static String createDummyLogbackConfigFile() - { - try - { - Path file = Files.createTempFile( "logback", ".xml" ); - Files.write( file, "".getBytes() ); - return file.toAbsolutePath().toString(); - } - catch ( IOException e ) - { - throw new RuntimeException( "Unable to create dummy logback configuration file", e ); - } - } - public static File getRelativeFile( Setting setting ) throws IOException { return getSharedTestTemporaryFolder() diff --git a/community/server/src/test/java/org/neo4j/server/configuration/ServerSettingsTest.java b/community/server/src/test/java/org/neo4j/server/configuration/ServerSettingsTest.java deleted file mode 100644 index 84f987afe305a..0000000000000 --- a/community/server/src/test/java/org/neo4j/server/configuration/ServerSettingsTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.server.configuration; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.UUID; - -import org.apache.commons.lang3.SystemUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.rules.TemporaryFolder; -import org.parboiled.common.FileUtils; - -import org.neo4j.graphdb.config.InvalidSettingException; -import org.neo4j.kernel.configuration.Config; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.IsEqual.equalTo; - -import static org.neo4j.helpers.collection.MapUtil.stringMap; -import static org.neo4j.kernel.configuration.Settings.TRUE; -import static org.neo4j.server.configuration.ServerSettings.http_log_config_file; -import static org.neo4j.server.configuration.ServerSettings.http_logging_enabled; - -public class ServerSettingsTest -{ - @Rule - public TemporaryFolder dir = new TemporaryFolder(); - - @Rule - public ExpectedException exception = ExpectedException.none(); - - @Test - public void shouldAllowWritableLogFileTarget() throws Throwable - { - // Given - File configFile = createHttpLogConfig( dir.newFile( "logfile" ) ); - - Config config = new Config( stringMap( - http_logging_enabled.name(), TRUE, - http_log_config_file.name(), configFile.getAbsolutePath() ), ServerSettings.class ); - - // When - File file = config.get( http_log_config_file ); - - // Then - assertThat( file.getAbsoluteFile(), equalTo( configFile.getAbsoluteFile() ) ); - } - - @Test - public void shouldFailToValidateHttpLogFileWithInvalidLogFileName() throws Throwable - { - // Given - File logFile = new File( createUnwritableDirectory(), "logfile" ); - File configFile = createHttpLogConfig( logFile ); - - - // Expect - exception.expect( InvalidSettingException.class ); - - // When - new Config( stringMap( - http_logging_enabled.name(), TRUE, - http_log_config_file.name(), configFile.getAbsolutePath() ), ServerSettings.class ); - } - - private File createHttpLogConfig( File logFile ) throws IOException - { - File configFile = dir.newFile( "http-logging.xml" ); - FileUtils.writeAllText( - "\n" + - " \n" + - " " + logFile.getAbsolutePath() + "\n" + - " \n" + - " /var/log/neo4j/http.%d{yyyy-MM-dd_HH}.log\n" + - " 7\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " %h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\" %D\n" + - " \n" + - " \n" + - "\n" + - " \n" + - "\n" + - "\n", configFile, StandardCharsets.UTF_8 ); - return configFile; - } - - public static File createUnwritableDirectory() - { - File file; - if ( SystemUtils.IS_OS_WINDOWS ) - { - file = new File( "\\\\" + UUID.randomUUID().toString() + "\\" ); - } - else if ( SystemUtils.IS_OS_MAC_OSX ) - { - file = new File( "/Network/Servers/localhost/" + UUID.randomUUID().toString() ); - } - else - { - file = new File( "/proc/" + UUID.randomUUID().toString() + "/random" ); - } - return file; - } -} diff --git a/community/server/src/test/java/org/neo4j/server/integration/ServerConfigIT.java b/community/server/src/test/java/org/neo4j/server/integration/ServerConfigIT.java index 263cbdd810e49..b5605a8209467 100644 --- a/community/server/src/test/java/org/neo4j/server/integration/ServerConfigIT.java +++ b/community/server/src/test/java/org/neo4j/server/integration/ServerConfigIT.java @@ -48,23 +48,6 @@ public class ServerConfigIT extends ExclusiveServerTestBase private CommunityNeoServer server; - @Test - public void serverConfigShouldBeVisibleInJMX() throws Throwable - { - // Given - String configValue = tempDir.newFile().getAbsolutePath(); - server = CommunityServerBuilder.server().withProperty( - ServerSettings.http_log_config_file.name(), configValue ) - .build(); - - // When - server.start(); - - // Then - ObjectName name = getObjectName( server.getDatabase().getGraph(), ConfigurationBean.CONFIGURATION_MBEAN_NAME ); - assertThat( getAttribute( name, ServerSettings.http_log_config_file.name() ), equalTo( (Object)configValue ) ); - } - @Test public void shouldBeAbleToOverrideShellConfig() throws Throwable { diff --git a/community/server/src/test/java/org/neo4j/server/preflight/EnsurePreparedForHttpLoggingTest.java b/community/server/src/test/java/org/neo4j/server/preflight/EnsurePreparedForHttpLoggingTest.java deleted file mode 100644 index 1c134c9d1b87e..0000000000000 --- a/community/server/src/test/java/org/neo4j/server/preflight/EnsurePreparedForHttpLoggingTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.server.preflight; - -import org.junit.Test; - -import org.neo4j.kernel.configuration.Config; -import org.neo4j.server.configuration.ServerSettings; - -import static java.util.Collections.singletonMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -public class EnsurePreparedForHttpLoggingTest -{ - @Test - public void shouldNotRunIfLoggingIsEnabledButConfigFileIsNull() - { - // Given - Config config = new Config( singletonMap( ServerSettings.http_logging_enabled.name(), "true" ) ); - EnsurePreparedForHttpLogging task = new EnsurePreparedForHttpLogging( config ); - - // When - boolean run = task.run(); - - // Then - assertFalse( run ); - assertEquals( "HTTP logging configuration file is not specified", task.getFailureMessage() ); - } -} diff --git a/community/server/src/test/java/org/neo4j/server/preflight/HTTPLoggingPreparednessRuleTest.java b/community/server/src/test/java/org/neo4j/server/preflight/HTTPLoggingPreparednessRuleTest.java deleted file mode 100644 index 363e1550177eb..0000000000000 --- a/community/server/src/test/java/org/neo4j/server/preflight/HTTPLoggingPreparednessRuleTest.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2002-2016 "Neo Technology," - * Network Engine for Objects in Lund AB [http://neotechnology.com] - * - * This file is part of Neo4j. - * - * Neo4j is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.neo4j.server.preflight; - -import org.apache.commons.lang.SystemUtils; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.UUID; - -import org.neo4j.graphdb.config.InvalidSettingException; -import org.neo4j.helpers.collection.MapUtil; -import org.neo4j.kernel.configuration.Config; -import org.neo4j.test.TargetDirectory; - -import static org.neo4j.server.configuration.ServerSettings.http_log_config_file; -import static org.neo4j.server.configuration.ServerSettings.http_logging_enabled; - -public class HTTPLoggingPreparednessRuleTest -{ - @Rule public ExpectedException exception = ExpectedException.none(); - - @Test - public void shouldPassWhenExplicitlyDisabled() - { - // given - Config config = new Config( MapUtil.stringMap( http_logging_enabled.name(), "false" ) ); - - // when - config.get( http_log_config_file ); - - // then no config error occurs - } - - @Test - public void shouldPassWhenImplicitlyDisabled() - { - // given - Config config = Config.empty(); - - // when - config.get( http_log_config_file ); - - // then no config error occurs - } - - @Test - public void shouldPassWhenEnabledWithGoodConfigSpecified() throws Exception - { - // given - File logDir = testDirectory.directory( "logDir" ); - File confDir = testDirectory.directory( "confDir" ); - Config config = new Config( MapUtil.stringMap( http_logging_enabled.name(), "true", - http_log_config_file.name(), createConfigFile( - createLogbackConfigXml( logDir ), confDir ).getAbsolutePath() ) ); - - // when - config.get( http_log_config_file ); - - // then no config error occurs - } - - @Test - public void shouldFailWhenEnabledWithUnwritableLogDirSpecifiedInConfig() throws Exception - { - // given - File confDir = testDirectory.directory( "confDir" ); - File unwritableDirectory = createUnwritableDirectory(); - Config config = new Config( MapUtil.stringMap( - http_logging_enabled.name(), "true", - http_log_config_file.name(), createConfigFile( createLogbackConfigXml( unwritableDirectory ), confDir ).getAbsolutePath() ) ); - - // expect - exception.expect( InvalidSettingException.class ); - - // when - config.get( http_log_config_file ); - - } - - @Rule - public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); - - public static File createUnwritableDirectory() - { - File file; - if ( SystemUtils.IS_OS_WINDOWS ) - { - file = new File( "\\\\" + UUID.randomUUID().toString() + "\\" ); - } - else if ( SystemUtils.IS_OS_MAC_OSX ) - { - file = new File( "/Network/Servers/localhost/" + UUID.randomUUID().toString() ); - } - else - { - file = new File( "/proc/" + UUID.randomUUID().toString() + "/random" ); - } - return file; - } - - public static File createConfigFile( String configXml, File location ) throws IOException - { - File configFile = new File( location.getAbsolutePath() + File.separator + "neo4j-logback-config.xml" ); - FileOutputStream fos = new FileOutputStream( configFile ); - fos.write( configXml.getBytes() ); - fos.close(); - return configFile; - } - - public static String createLogbackConfigXml( File logDirectory ) - { - return createLogbackConfigXml( logDirectory, "%h %l %user [%t{dd/MMM/yyyy:HH:mm:ss Z}] \"%r\" %s %b \"%i{Referer}\" \"%i{User-Agent}\"" ); - } - - public static String createLogbackConfigXml( File logDirectory, String logPattern ) - { - return "\n" + - " \n" + - " " + logDirectory.getAbsolutePath() + File.separator + "http.log\n" + - " \n" + - " " + logDirectory.getAbsolutePath() + File.separator + "http.%d{yyyy-MM-dd_HH}.log\n" + - " 30\n" + - " \n" + - "\n" + - " \n" + - " \n" + - " "+logPattern+"\n" + - " \n" + - " \n" + - "\n" + - " \n" + - ""; - } -} diff --git a/community/server/src/test/java/org/neo4j/server/web/logging/HTTPLoggingDocIT.java b/community/server/src/test/java/org/neo4j/server/web/logging/HTTPLoggingDocIT.java index 25605e34dbf3c..0616947210876 100644 --- a/community/server/src/test/java/org/neo4j/server/web/logging/HTTPLoggingDocIT.java +++ b/community/server/src/test/java/org/neo4j/server/web/logging/HTTPLoggingDocIT.java @@ -19,42 +19,29 @@ */ package org.neo4j.server.web.logging; -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.SystemUtils; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; - import org.neo4j.function.ThrowingSupplier; -import org.neo4j.graphdb.config.InvalidSettingException; -import org.neo4j.helpers.collection.MapUtil; -import org.neo4j.kernel.configuration.Config; +import org.neo4j.graphdb.factory.GraphDatabaseSettings; import org.neo4j.server.NeoServer; import org.neo4j.server.configuration.ServerSettings; import org.neo4j.server.helpers.CommunityServerBuilder; import org.neo4j.server.helpers.FunctionalTestHelper; -import org.neo4j.server.preflight.EnsurePreparedForHttpLogging; -import org.neo4j.server.preflight.HTTPLoggingPreparednessRuleTest; import org.neo4j.server.rest.JaxRsResponse; import org.neo4j.server.rest.RestRequest; import org.neo4j.test.TargetDirectory; import org.neo4j.test.server.ExclusiveServerTestBase; -import org.neo4j.test.server.HTTP; -import static org.hamcrest.CoreMatchers.containsString; +import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.UUID; + import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assume.assumeThat; - import static org.neo4j.io.fs.FileUtils.readTextFile; -import static org.neo4j.test.Assert.assertEventually; -import static org.neo4j.test.server.HTTP.RawPayload.rawPayload; public class HTTPLoggingDocIT extends ExclusiveServerTestBase { @@ -71,12 +58,9 @@ public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesse "givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses-confdir" ); FileUtils.forceMkdir( confDir ); - final File configFile = HTTPLoggingPreparednessRuleTest.createConfigFile( - HTTPLoggingPreparednessRuleTest.createLogbackConfigXml( logDirectory ), confDir ); - NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning() .withProperty( ServerSettings.http_logging_enabled.name(), "false" ) - .withProperty( ServerSettings.http_log_config_file.name(), configFile.getPath() ) + .withProperty( GraphDatabaseSettings.logs_directory.name(), logDirectory.toString() ) .usingDataDir( testDirectory.directory( "givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses-dbdir" ).getAbsolutePath() ) @@ -102,149 +86,12 @@ public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesse } } - @Test - public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception - { - // given - final File logDirectory = - testDirectory.directory( "givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess-logdir" ); - FileUtils.forceMkdir( logDirectory ); - final File confDir = - testDirectory.directory( "givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess-confdir" ); - FileUtils.forceMkdir( confDir ); - - final File configFile = HTTPLoggingPreparednessRuleTest.createConfigFile( - HTTPLoggingPreparednessRuleTest.createLogbackConfigXml( logDirectory ), confDir ); - - final String query = "?explicitlyEnabled=" + randomString(); - - NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning() - .withProperty( ServerSettings.http_logging_enabled.name(), "true" ) - .withProperty( ServerSettings.http_log_config_file.name(), configFile.getPath() ) - .usingDataDir( testDirectory.directory( - "givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess-dbdir" - ).getAbsolutePath() ) - .build(); - try - { - server.start(); - - FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper( server ); - - // when - JaxRsResponse response = new RestRequest().get( functionalTestHelper.managementUri() + query ); - assertThat( response.getStatus(), is( 200 ) ); - response.close(); - - // then - File httpLog = new File( logDirectory, "http.log" ); - assertEventually( "request appears in log", fileContentSupplier( httpLog ), containsString( query ), 5, TimeUnit.SECONDS ); - } - finally - { - server.stop(); - } - } - - @Test - public void givenDebugContentLoggingEnabledShouldLogContent() throws Exception - { - // given - final File logDirectory = testDirectory.directory( "givenDebugContentLoggingEnabledShouldLogContent-logdir" ); - FileUtils.forceMkdir( logDirectory ); - final File confDir = testDirectory.directory( "givenDebugContentLoggingEnabledShouldLogContent-confdir" ); - FileUtils.forceMkdir( confDir ); - - final File configFile = HTTPLoggingPreparednessRuleTest.createConfigFile( - HTTPLoggingPreparednessRuleTest.createLogbackConfigXml( logDirectory, "$requestContent\n%responseContent" ), confDir ); - - NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning() - .withProperty( ServerSettings.http_logging_enabled.name(), "true" ) - .withProperty( ServerSettings.http_content_logging_enabled.name(), "true" ) - .withProperty( ServerSettings.http_log_config_file.name(), configFile.getPath() ) - .usingDataDir( testDirectory.directory( "givenDebugContentLoggingEnabledShouldLogContent-datadir" ) - .getAbsolutePath() ) - .build(); - - try - { - server.start(); - - // when - HTTP.Response req = HTTP.POST( server.baseUri().resolve( "/db/data/node" ).toString(), rawPayload( "{\"name\":\"Hello, world!\"}" ) ); - assertThat( req.status(), is( 201 ) ); - - // then - File httpLog = new File( logDirectory, "http.log" ); - assertEventually( "request appears in log", fileContentSupplier( httpLog ), containsString( "Hello, world!" ), 5, TimeUnit.SECONDS ); - assertEventually( "request appears in log", fileContentSupplier( httpLog ), containsString( "metadata" ), 5, TimeUnit.SECONDS ); - } - finally - { - server.stop(); - } - } - - @Test - public void givenConfigurationWithUnwritableLogDirectoryShouldFailToStartServer() throws Exception - { - // given - final File confDir = testDirectory.directory( "confdir" ); - final File unwritableLogDir = createUnwritableDirectory(); - - final File configFile = HTTPLoggingPreparednessRuleTest.createConfigFile( - HTTPLoggingPreparednessRuleTest.createLogbackConfigXml( unwritableLogDir ), confDir ); - - Config config = new Config( MapUtil.stringMap( - ServerSettings.http_logging_enabled.name(), "true", - ServerSettings.http_log_config_file.name(), configFile.getPath() ) ); - - // expect - exception.expect( InvalidSettingException.class ); - - // when - NeoServer server = CommunityServerBuilder.server().withDefaultDatabaseTuning() - .withPreflightTasks( new EnsurePreparedForHttpLogging( config ) ) - .withProperty( ServerSettings.http_logging_enabled.name(), "true" ) - .withProperty( ServerSettings.http_log_config_file.name(), configFile.getPath() ) - .usingDataDir( confDir.getAbsolutePath() ) - .build(); - } - @Rule public final TargetDirectory.TestDirectory testDirectory = TargetDirectory.testDirForTest( getClass() ); private ThrowingSupplier fileContentSupplier( final File file ) { - return new ThrowingSupplier() - { - @Override - public String get() throws IOException - { - return readTextFile( file, StandardCharsets.UTF_8 ); - } - }; - } - - private File createUnwritableDirectory() - { - File file; - if ( SystemUtils.IS_OS_WINDOWS ) - { - file = new File( "\\\\" + randomString() + "\\http.log" ); - } - else - { - file = testDirectory.file( "unwritable-" + randomString() ); - assertThat( "create directory to be unwritable", file.mkdirs(), is( true ) ); - - // Assume that we can change the file permissions, and that permissions are respected. - // If these checks fail, then we cannot use the current file system for this test, so we bail. - assumeThat( "mark directory as unwritable", file.setWritable( false, false ), is( true ) ); - assumeThat( "directory permissions are respected", file.canWrite(), is( false ) ); - } - - return file; + return () -> readTextFile( file, StandardCharsets.UTF_8 ); } private String randomString() diff --git a/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java b/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java index 1770a6724ce7f..1a3db8d048abe 100644 --- a/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java +++ b/integrationtests/src/test/java/org/neo4j/server/BatchEndpointIT.java @@ -27,7 +27,6 @@ import org.neo4j.server.configuration.ServerSettings; import static org.junit.Assert.assertEquals; -import static org.neo4j.server.ServerTestUtils.createDummyLogbackConfigFile; import static org.neo4j.server.ServerTestUtils.getRelativePath; import static org.neo4j.server.ServerTestUtils.getSharedTestTemporaryFolder; import static org.neo4j.test.server.HTTP.RawPayload.quotedJson; @@ -39,7 +38,6 @@ public class BatchEndpointIT @Rule public final Neo4jRule neo4j = new Neo4jRule() .withConfig( ServerSettings.http_logging_enabled, "true" ) - .withConfig( ServerSettings.http_log_config_file, createDummyLogbackConfigFile() ) .withConfig( ServerSettings.tls_key_file.name(), getRelativePath( getSharedTestTemporaryFolder(), ServerSettings.tls_key_file ) ) .withConfig( ServerSettings.tls_certificate_file.name(), diff --git a/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java b/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java index 8693f8a06c4e1..2b23fff8b25d1 100644 --- a/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java +++ b/integrationtests/src/test/java/org/neo4j/server/BoltQueryLoggingIT.java @@ -38,7 +38,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.junit.Assert.assertTrue; -import static org.neo4j.server.ServerTestUtils.createDummyLogbackConfigFile; import static org.neo4j.server.ServerTestUtils.getRelativePath; import static org.neo4j.server.ServerTestUtils.getSharedTestTemporaryFolder; @@ -56,7 +55,6 @@ public BoltQueryLoggingIT() throws IOException queriesLog.deleteOnExit(); this.neo4j = new Neo4jRule() .withConfig( ServerSettings.http_logging_enabled, "true" ) - .withConfig( ServerSettings.http_log_config_file, createDummyLogbackConfigFile() ) .withConfig( ServerSettings.tls_key_file.name(), getRelativePath( getSharedTestTemporaryFolder(), ServerSettings.tls_key_file ) ) .withConfig( ServerSettings.tls_certificate_file.name(),