Skip to content

Commit

Permalink
Log HTTP requests using our own async logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
srbaker committed Mar 23, 2016
1 parent 1feb7c6 commit 079d510
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 700 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand Down
Expand Up @@ -173,14 +173,6 @@ private ThirdPartyJaxRsPackage createThirdPartyJaxRsPackage( String packageAndMo
@Description("Enable HTTP request logging.")
Setting<Boolean> http_logging_enabled = setting( "org.neo4j.server.http.log.enabled", BOOLEAN, FALSE );

@Description("Enable HTTP content logging.")
Setting<Boolean> 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<File> 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<Boolean> gc_logging_enabled = setting("dbms.logs.gc.enabled", BOOLEAN, FALSE);
Expand Down

This file was deleted.

Expand Up @@ -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;
Expand All @@ -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<OutputStream> outputSupplier = new RotatingFileOutputStreamSupplier(
Expand All @@ -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 );
}
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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" );
}
}

Expand Down Expand Up @@ -408,7 +398,7 @@ else if ( isJaxrsClass )
}
}

if ( requestLoggingConfiguration != null )
if ( requestLogFile != null )
{
loadRequestLogging();
}
Expand All @@ -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();
Expand Down
Expand Up @@ -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 );

Expand Down
Expand Up @@ -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, "<configuration></configuration>".getBytes() );
return file.toAbsolutePath().toString();
}
catch ( IOException e )
{
throw new RuntimeException( "Unable to create dummy logback configuration file", e );
}
}

public static File getRelativeFile( Setting<File> setting ) throws IOException
{
return getSharedTestTemporaryFolder()
Expand Down

0 comments on commit 079d510

Please sign in to comment.