Correct and better logging of exceptions

Change-Id: I866b5bdabf8dd1eadb1fe68f93038cbb43d6e328
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
index a916717..9a9cde1 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -797,7 +797,7 @@
                     } catch (DataModelException e) {
                         throw e;
                     } catch (CloneNotSupportedException e) {
-                        e.printStackTrace();
+                        log.error("Error in cloning", e);
                         throw new DataModelException("Could not clone Type node " +
                                                              leaf.getDataType().getDataTypeName() + " in " +
                                                              leaf.getDataType().getLineNumber() + " at " +
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
index f2ae7e7..ff01a38 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangCompilerManager.java
@@ -200,7 +200,7 @@
                         translatorErrorHandler(curYangFileInfo.getRootNode(),
                                                config);
                     } catch (IOException ex) {
-                        e.printStackTrace();
+                        log.error("Error in processing the files", e);
                         throw ex;
                     }
                 }
diff --git a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
index 49fb160..3aee6d8 100644
--- a/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
+++ b/runtime/src/test/java/org/onosproject/yang/runtime/impl/DefaultYangModelRegistryTest.java
@@ -25,6 +25,7 @@
 import org.onosproject.yang.model.YangModel;
 import org.onosproject.yang.model.YangModule;
 import org.onosproject.yang.model.YangModuleId;
+import org.slf4j.Logger;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -41,12 +42,15 @@
 import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.processSchemaRegistry;
 import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.registry;
 import static org.onosproject.yang.runtime.impl.MockYangSchemaNodeProvider.unRegister;
+import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  * Unit test for model registry.
  */
 public class DefaultYangModelRegistryTest {
 
+    private static final Logger log = getLogger(DefaultYangModelRegistryTest.class);
+
     private static final String SCHEMA_NAME_3 = "ietf-network3";
     private static final String INTERFACE_NAME_3 =
             "org.onosproject.yang.gen.v1.ietfnetwork3.rev20151208.IetfNetwork3";
@@ -166,7 +170,7 @@
         try {
             node = ((YangNode) objectInputStream.readObject());
         } catch (ClassNotFoundException e) {
-            System.out.println(e);
+            log.error("Class not found", e);
         }
         objectInputStream.close();
         assertThat(true, is(
diff --git a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
index 2c401f9..0790687 100644
--- a/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
+++ b/serializers/json/src/main/java/org/onosproject/yang/serializers/json/DefaultJsonBuilder.java
@@ -204,7 +204,8 @@
             m.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
             node = (ObjectNode) m.readTree(getTreeString());
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("Error in processing the tree", e);
+            log.debug("tree {}", getTreeString());
         }
         return node;
     }
diff --git a/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java b/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
index 1667674..9feeba5 100644
--- a/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
+++ b/serializers/json/src/test/java/org/onosproject/yang/serializers/json/JsonSerializerTest.java
@@ -37,6 +37,7 @@
 import org.onosproject.yang.runtime.RuntimeContext;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.YangSerializerContext;
+import org.slf4j.Logger;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -53,12 +54,15 @@
 import static org.hamcrest.core.Is.is;
 import static org.junit.Assert.assertEquals;
 import static org.onosproject.yang.serializers.utils.SerializersUtil.convertRidToUri;
+import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  * Unit Test for Json Serializer.
  */
 public class JsonSerializerTest {
 
+    private static final Logger log = getLogger(JsonSerializerTest.class);
+
     private static YangSerializerContext context;
     private static YangSerializer jsonSerializer;
 
@@ -342,7 +346,7 @@
                 sb.append(temp);
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("Error in processing the path {}", path, e);
         }
         return IOUtils.toInputStream(sb);
     }
@@ -362,7 +366,7 @@
                 sb.append(temp);
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("Error in processing the path {}", path, e);
         }
         return sb.toString();
     }
diff --git a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
index fe5f4ce..ff9a0e2 100644
--- a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
+++ b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
@@ -40,6 +40,7 @@
 import org.onosproject.yang.runtime.DefaultCompositeStream;
 import org.onosproject.yang.runtime.YangSerializer;
 import org.onosproject.yang.runtime.YangSerializerContext;
+import org.slf4j.Logger;
 
 import java.io.BufferedReader;
 import java.io.FileReader;
@@ -52,12 +53,15 @@
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.slf4j.LoggerFactory.getLogger;
 
 /**
  *
  */
 public class XmlSerializerTest {
 
+    private static final Logger log = getLogger(XmlSerializerTest.class);
+
     public static final String LNS = "yrt:list.anydata";
     private static final String LIST_NS = "yrt:list";
     private static YangSerializerContext context;
@@ -232,7 +236,7 @@
                 sb.append(temp);
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("Error in processing the path {}", path, e);
         }
         return IOUtils.toInputStream(sb);
     }