/*
 * Copyright 2012 Mozilla Foundation
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mozilla.bagheera.sink;

import java.io.IOException;

import org.apache.log4j.Logger;

public class LoggerSink implements Sink, KeyValueSink {

    private static final Logger LOG = Logger.getLogger(LoggerSink.class);
    
    private boolean logValues;
    
    public LoggerSink(SinkConfiguration sinkConfiguration) {
        this(sinkConfiguration.getBoolean("loggersink.logvalues", false));
    }
    
    public LoggerSink(boolean logValues) {
        this.logValues = logValues;
    }
    
    @Override
    public void close() {
        LOG.info("Called close()");
    }
    
    @Override
    public void store(byte[] data) throws IOException {
        LOG.info("data length:" + data.length);
        if (logValues) {
            LOG.info("data: " + new String(data, "UTF-8"));
        }
    }
    
    @Override
    public void store(String key, byte[] data) throws IOException {
        LOG.info("Called store(key,data)");
        LOG.info("key length: " + key.length());
        LOG.info("data length:" + data.length);
        if (logValues) {
            LOG.info("key: " + key);
            LOG.info("data: " + new String(data, "UTF-8"));
        }
    }

    @Override
    public void store(String key, byte[] data, long timestamp) throws IOException {
        LOG.info("Called store(key,data,timestamp)");
        LOG.info("key length: " + key.length());
        LOG.info("data length:" + data.length);
        LOG.info("timestamp: " + timestamp);
        if (logValues) {
            LOG.info("key: " + key);
            LOG.info("data: " + new String(data, "UTF-8"));
        }    
    }

    @Override
    public void delete(String key) {
        LOG.info("Called delete(key)");
        LOG.info("key length: " + key.length());
        if (logValues) {
            LOG.info("key: " + key);
        }
    }

}

@@ -1066,20 +1066,16 @@
 class);%0A
-    
 %0A    pri
@@ -1098,20 +1098,16 @@
 Values;%0A
-    
 %0A    pub
@@ -1237,28 +1237,24 @@
 se));%0A    %7D%0A
-    
 %0A    public 
@@ -1319,36 +1319,32 @@
 ogValues;%0A    %7D%0A
-    
 %0A    @Override%0A 
@@ -1406,28 +1406,24 @@
 ()%22);%0A    %7D%0A
-    
 %0A    @Overri
@@ -1491,32 +1491,81 @@
       LOG.info(%22
+Called store(data)%22);%0A        LOG.info(%22store(d) 
 data length:%22 + 
@@ -1617,32 +1617,41 @@
       LOG.info(%22
+store(d) 
 data: %22 + new St
@@ -1688,20 +1688,16 @@
 %7D%0A    %7D%0A
-    
 %0A    @Ov
@@ -1825,32 +1825,43 @@
       LOG.info(%22
+store(k,d) 
 key length: %22 + 
@@ -1885,32 +1885,43 @@
       LOG.info(%22
+store(k,d) 
 data length:%22 + 
@@ -1973,32 +1973,43 @@
       LOG.info(%22
+store(k,d) 
 key: %22 + key);%0A 
@@ -2021,32 +2021,43 @@
       LOG.info(%22
+store(k,d) 
 data: %22 + new St
@@ -2257,32 +2257,45 @@
       LOG.info(%22
+store(k,d,t) 
 key length: %22 + 
@@ -2323,24 +2323,37 @@
   LOG.info(%22
+store(k,d,t) 
 data length:
@@ -2388,16 +2388,29 @@
 G.info(%22
+store(k,d,t) 
 timestam
@@ -2467,32 +2467,45 @@
       LOG.info(%22
+store(k,d,t) 
 key: %22 + key);%0A 
@@ -2525,16 +2525,29 @@
 G.info(%22
+store(k,d,t) 
 data: %22 
@@ -2585,20 +2585,16 @@
        %7D
-    
 %0A    %7D%0A%0A
@@ -2702,16 +2702,26 @@
 G.info(%22
+delete(k) 
 key leng
@@ -2790,16 +2790,26 @@
 G.info(%22
+delete(k) 
 key: %22 +

Make the LoggerSink output more greppable