move objectMapper into requestLogger

This commit is contained in:
xvrl 2013-03-07 11:31:36 -08:00
parent 21d648cc39
commit b0349a6518
5 changed files with 16 additions and 9 deletions

View File

@ -248,7 +248,7 @@ public abstract class QueryableNode<T extends 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);

View File

@ -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();
}

View File

@ -93,7 +93,7 @@ public class QueryServlet extends HttpServlet
query = objectMapper.readValue(requestQuery, Query.class);
requestLogger.log(
new RequestLogLine(new DateTime(), req.getRemoteAddr(), jsonMapper.writer().writeValueAsString(query))
new RequestLogLine(new DateTime(), req.getRemoteAddr(), query)
);
Sequence<?> results = query.run(texasRanger);

View File

@ -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;
@ -31,22 +33,22 @@ public class RequestLogLine
private final DateTime timestamp;
private final String remoteAddr;
private final String query;
private final Query query;
public RequestLogLine(DateTime timestamp, String remoteAddr, String query)
public RequestLogLine(DateTime timestamp, String remoteAddr, Query query)
{
this.timestamp = timestamp;
this.remoteAddr = remoteAddr;
this.query = query;
}
public String getLine()
public String getLine(ObjectMapper objectMapper) throws JsonProcessingException
{
return JOINER.join(
Arrays.asList(
timestamp,
remoteAddr,
query
objectMapper.writeValueAsString(query)
)
);
}

View File

@ -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"))
);