diff --git a/client/src/main/java/com/metamx/druid/QueryableNode.java b/client/src/main/java/com/metamx/druid/QueryableNode.java index 749b2bd8b40..a9a97ec64af 100644 --- a/client/src/main/java/com/metamx/druid/QueryableNode.java +++ b/client/src/main/java/com/metamx/druid/QueryableNode.java @@ -248,7 +248,7 @@ public abstract class QueryableNode extends Registering { if (requestLogger == null) { try { - setRequestLogger(Initialization.makeRequestLogger(getScheduledExecutorFactory(), getProps())); + setRequestLogger(Initialization.makeRequestLogger(getJsonMapper(), getScheduledExecutorFactory(), getProps())); } catch (IOException e) { throw Throwables.propagate(e); diff --git a/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java b/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java index 20425f9eb37..110e72f1c6f 100644 --- a/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java +++ b/client/src/main/java/com/metamx/druid/http/FileRequestLogger.java @@ -19,6 +19,7 @@ package com.metamx.druid.http; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Throwables; import com.google.common.io.Closeables; import com.metamx.common.concurrent.ScheduledExecutors; @@ -38,6 +39,7 @@ import java.util.concurrent.ScheduledExecutorService; */ public class FileRequestLogger implements RequestLogger { + private final ObjectMapper objectMapper; private final ScheduledExecutorService exec; private final File baseDir; @@ -46,9 +48,11 @@ public class FileRequestLogger implements RequestLogger private volatile DateTime currentDay; private volatile FileWriter fileWriter; - public FileRequestLogger(ScheduledExecutorService exec, File baseDir) + + public FileRequestLogger(ObjectMapper objectMapper, ScheduledExecutorService exec, File baseDir) { this.exec = exec; + this.objectMapper = objectMapper; this.baseDir = baseDir; } @@ -110,7 +114,7 @@ public class FileRequestLogger implements RequestLogger { synchronized (lock) { fileWriter.write( - String.format("%s%n", requestLogLine.getLine()) + String.format("%s%n", requestLogLine.getLine(objectMapper)) ); fileWriter.flush(); } diff --git a/client/src/main/java/com/metamx/druid/http/RequestLogLine.java b/client/src/main/java/com/metamx/druid/http/RequestLogLine.java index e42be46fff6..452bd65656e 100644 --- a/client/src/main/java/com/metamx/druid/http/RequestLogLine.java +++ b/client/src/main/java/com/metamx/druid/http/RequestLogLine.java @@ -19,6 +19,8 @@ package com.metamx.druid.http; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Joiner; import com.metamx.druid.Query; import org.joda.time.DateTime; @@ -40,14 +42,14 @@ public class RequestLogLine this.query = query; } - public String getLine() + public String getLine(ObjectMapper objectMapper) throws JsonProcessingException { return JOINER.join( Arrays.asList( timestamp, remoteAddr, - query + objectMapper.writeValueAsString(query) ) ); } -} \ No newline at end of file +} diff --git a/client/src/main/java/com/metamx/druid/initialization/Initialization.java b/client/src/main/java/com/metamx/druid/initialization/Initialization.java index ba3b42d56e1..d173f5a95f7 100644 --- a/client/src/main/java/com/metamx/druid/initialization/Initialization.java +++ b/client/src/main/java/com/metamx/druid/initialization/Initialization.java @@ -348,9 +348,10 @@ public class Initialization return serviceProvider; } - public static RequestLogger makeRequestLogger(ScheduledExecutorFactory factory, Properties props) throws IOException + public static RequestLogger makeRequestLogger(ObjectMapper objectMapper, ScheduledExecutorFactory factory, Properties props) throws IOException { return new FileRequestLogger( + objectMapper, factory.create(1, "RequestLogger-%s"), new File(PropUtils.getProperty(props, "druid.request.logging.dir")) );