/*
 */
package org.datadryad.rest.handler;

import java.io.IOException;
import org.apache.log4j.Logger;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.ObjectWriter;
import org.datadryad.rest.storage.StoragePath;

/**
 *
 * @author Dan Leehr <dan.leehr@nescent.org>
 */
public class LoggingHandler<T> implements HandlerInterface<T>{
    private static final Logger log = Logger.getLogger(LoggingHandler.class);
    ObjectWriter writer;

    public LoggingHandler() {
        ObjectMapper mapper = new ObjectMapper();
        writer = mapper.writerWithDefaultPrettyPrinter();
    }

    private void logObject(String method, T object) {
        String objectString = "";
        try {
            objectString = writer.writeValueAsString(object);
        } catch (IOException ex) {
            log.error("IO Exception writing logging json object");
        }
        String message = String.format("%s\n%s", method, objectString);
        log.info(message);
    }

    @Override
    public void handleCreate(StoragePath path, T object) throws HandlerException {
        String method = "REST Create " + path.toString();
        logObject(method, object);
    }

    @Override
    public void handleUpdate(StoragePath path, T object) throws HandlerException {
        String method = "REST Update " + path.toString();
        logObject(method, object);
    }

    @Override
    public void handleDelete(StoragePath path, T object) throws HandlerException {
        String method = "REST Delete " + path.toString();
        logObject(method, object);
    }

}

@@ -65,16 +65,51 @@
 eption;%0A
+import java.text.SimpleDateFormat;%0A
 import o
@@ -128,24 +128,24 @@
 g4j.Logger;%0A
-
 import org.c
@@ -220,24 +220,79 @@
 jectWriter;%0A
+import org.codehaus.jackson.util.DefaultPrettyPrinter;%0A
 import org.d
@@ -379,16 +379,81 @@
 nt.org%3E%0A
+ * @param %3CT%3E A type that can be serialized to JSON with jackson%0A
  */%0Apubl
@@ -703,16 +703,144 @@
         
+mapper.setSerializationConfig(mapper.getSerializationConfig().withDateFormat(new SimpleDateFormat(%22yyyy-MM-dd%22)));%0A        this.
 writer =
@@ -857,12 +857,13 @@
 iter
-With
+(new 
 Defa
@@ -876,24 +876,25 @@
 ttyPrinter()
+)
 ;%0A    %7D%0A%0A   
@@ -1405,16 +1405,17 @@
 T Create
+:
  %22 + pat
@@ -1603,16 +1603,17 @@
 T Update
+:
  %22 + pat
@@ -1757,32 +1757,32 @@
 dlerException %7B%0A
-
         String m
@@ -1801,16 +1801,17 @@
 T Delete
+:
  %22 + pat

Add date formatting to JSON logging