import org.onap.cli.fw.output.ResultType;
 import org.onap.cli.fw.utils.ExternalSchema;
 import org.onap.cli.fw.utils.OnapCommandUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Onap Command registrar provides a common place, where every command would get registered automatically when its
  */
 public class OnapCommandRegistrar {
 
+    private static Logger LOG = LoggerFactory.getLogger(OnapCommandRegistrar.class);
+
     private Map<String, Class<? extends OnapCommand>> registry = new HashMap<>();
 
     private Set<String> availableProductVersions = new HashSet<>();
 
     private static final long serialVersionUID = 8580121615330415000L;
     private static final String ERROR_CODE = "0x0021";
     private static final String ERROR_MESSAGE1 = "API client for the command ";
-    private static final String ERROR_MESSAGE2 = " is failed, ";
+    private static final String ERROR_MESSAGE2 = " is failed";
 
     public OnapCommandClientInitialzationFailed(String cmd, String error) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + cmd + ERROR_MESSAGE2 + error);
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmd + ERROR_MESSAGE2 + ", " + error);
     }
 
     public OnapCommandClientInitialzationFailed(String cmd, Throwable throwable) {
-        this(cmd, throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmd + ERROR_MESSAGE2, throwable);
     }
 }
 
     }
 
     public OnapCommandDiscoveryFailed(String directory, String fileName) {
-        this(directory, fileName, new Exception(""));
+        super(ERROR_CODE, ERROR_MESSAGE4 + fileName + ERROR_MESSAGE3 + directory + "'");
     }
 
     public OnapCommandDiscoveryFailed(String directory, String fileName, Throwable throwable) {
-        super(ERROR_CODE, ERROR_MESSAGE4 + fileName + ERROR_MESSAGE3 + directory + "' , " + throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE4 + fileName + ERROR_MESSAGE3 + directory + "'", throwable);
     }
 }
 
 
 package org.onap.cli.fw.error;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 /**
  * Base command exception.
  *
 
     private static final long serialVersionUID = 2833124031431731711L;
 
+    private static Logger LOG = LoggerFactory.getLogger(OnapCommandException.class);
+
     /*
      * Command Error Code
      */
         return message;
     }
 
+    public OnapCommandException(String errorCode, String errorMessage, Throwable e) {
+        this(errorCode, errorMessage + ", " + e.getMessage());
+        LOG.error(this.getMessage(), e);
+    }
+
+    public OnapCommandException(String errorCode, String errorMessage, Throwable e, long httpStatusCode) {
+        this(errorCode, errorMessage + ", " + e.getMessage(), httpStatusCode);
+        LOG.error(this.getMessage(), e);
+    }
+
+    public OnapCommandException(String errorCode, Throwable e, long httpStatusCode) {
+        this(errorCode, e.getMessage(), httpStatusCode);
+        LOG.error(this.getMessage(), e);
+    }
+
+    public OnapCommandException(String errorCode, Throwable e) {
+        this(errorCode, e.getMessage(), -1);
+        LOG.error(this.getMessage(), e);
+    }
+
+    public String getErrorCode() {
+        return this.errorCode;
+    }
 }
 
 
     private static final String ERROR_CODE = "0x0001";
     private static final String ERROR_MESSAGE1 = "Command ";
-    private static final String ERROR_MESSAGE2 = " failed to execute, ";
-    private static final String ERROR_MESSAGE3 = "Failed to retrive service url, ";
+    private static final String ERROR_MESSAGE2 = " failed to execute";
+    private static final String ERROR_MESSAGE3 = "Failed to retrive service url";
 
     public OnapCommandExecutionFailed(String cmdName, String  error, long httpStatus) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + cmdName + ERROR_MESSAGE2 + error, httpStatus);
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmdName + ERROR_MESSAGE2 + ", " + error, httpStatus);
     }
 
     public OnapCommandExecutionFailed(String cmdName, Throwable throwable, long httpStatus) {
-        this(cmdName,throwable.getMessage(),httpStatus);
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmdName + ERROR_MESSAGE2 ,throwable, httpStatus);
     }
 
     public OnapCommandExecutionFailed(String  error) {
     }
 
     public OnapCommandExecutionFailed(Throwable throwable, String  details) {
-        this(ERROR_MESSAGE3 + details + ", " + throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE3 + ", " +details, throwable);
     }
 
 
     public OnapCommandExecutionFailed(String cmdName, String  error) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + cmdName + ERROR_MESSAGE2 + error);
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmdName + ERROR_MESSAGE2 + ", " + error);
     }
 
     public OnapCommandExecutionFailed(String cmd, Throwable throwable) {
-        this(cmd , throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE1 + cmd + ERROR_MESSAGE2 , throwable);
     }
 }
 
 public class OnapCommandHelpFailed extends OnapCommandException {
     private static final long serialVersionUID = -1833571383961748518L;
 
+    private static final String ERROR_CODE = "0x0002";
+
+    private static final String ERROR_MSG = "Command failed to print help message";
     /**
      * Help failed exception.
      *
      *            message
      */
     public OnapCommandHelpFailed(String error) {
-        super("0x0002", "Command failed to print help message, " + error);
+        super(ERROR_CODE, ERROR_MSG + ", " + error);
     }
 
     public OnapCommandHelpFailed(Throwable throwable) {
-        this(throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG, throwable);
     }
 }
 
 public class OnapCommandHttpFailure extends OnapCommandException {
     private static final long serialVersionUID = 488775545436993345L;
 
-    private static final String ERROR = "0x0025";
+    private static final String ERROR_CODE = "0x0025";
 
     public OnapCommandHttpFailure(String error, long httpStatus) {
-        super(ERROR, error, httpStatus);
+        super(ERROR_CODE, error, httpStatus);
     }
 
     public OnapCommandHttpFailure(String error) {
-        super(ERROR, error);
+        super(ERROR_CODE, error);
     }
 
     public OnapCommandHttpFailure(Throwable throwable) {
-        this(throwable.getMessage());
+        super(ERROR_CODE, throwable);
     }
 
     public OnapCommandHttpFailure(Throwable throwable, long httpStatus) {
-        this(throwable.getMessage(), httpStatus);
+        super(ERROR_CODE, throwable, httpStatus);
     }
 
 }
 
 
     private static final long serialVersionUID = 6676137916079057963L;
 
+    private static final String ERROR_CODE = "0x0028";
+    private static final String ERR_MSG = "Http response body does not have json entry ";
+
     public OnapCommandHttpInvalidResponseBody(String name, String error) {
-        super("0x0028", "Http response body does not have json entry " + name + ", " + error);
+        super(ERROR_CODE, ERR_MSG + name + ", " + error);
     }
 
     public OnapCommandHttpInvalidResponseBody(String name, Throwable throwable) {
-        this(name, throwable.getMessage());
+        super(ERROR_CODE, ERR_MSG + name, throwable);
     }
 }
 
     }
 
     public OnapCommandInvalidParameterValue(String paramName, Throwable throwable) {
-        super("0x0028", "Parameter " + paramName + " value is invalid, " + throwable.getMessage());
+        super("0x0028", "Parameter " + paramName + " value is invalid", throwable);
     }
 
 }
 
 
     private static final long serialVersionUID = -3387652326582792833L;
 
+    private static final String ERROR_CODE = "0x0007";
+
+    private static final String ERROR_MSG = "Invalid command schema ";
+
     public OnapCommandInvalidSchema(String error) {
-        this("", error);
+        this(ERROR_CODE, error);
     }
 
     public OnapCommandInvalidSchema(String schema, String error) {
-        super("0x0007", "Command schema " + schema + " is invalid, " + error);
+        super(ERROR_CODE, ERROR_MSG + schema + ", " + error);
     }
 
     public OnapCommandInvalidSchema(String schema, Throwable throwable) {
-        this(schema, throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG + schema , throwable);
     }
 
 }
 
 
     private static final long serialVersionUID = 8580121615330415123L;
 
+    private static final String ERROR_CODE = "0x1301";
+
+    private static final String ERROR_MSG = "Failed to load profile details";
     /**
      * Command result empty.
      */
     public OnapCommandLoadProfileFailed(String error) {
-        super("0x1301", "Failed to load profile details, " + error);
+        super(ERROR_CODE, ERROR_MSG + ", " + error);
     }
 
     public OnapCommandLoadProfileFailed(Throwable error) {
-        this(error.getMessage());
+        super(ERROR_CODE, ERROR_MSG, error);
     }
 
 }
 
     private static final long serialVersionUID = 5518154493762956959L;
 
     private static final String ERROR_CODE = "0x0009";
-    private static final String ERROR_MESSAGE1 = "Login failed, ";
+    private static final String ERROR_MESSAGE1 = "Login failed";
 
     public OnapCommandLoginFailed(String error) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + error);
+        super(ERROR_CODE, ERROR_MESSAGE1 + ", " + error);
     }
 
     public OnapCommandLoginFailed(String error, int httpStatus) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + error, httpStatus);
+        super(ERROR_CODE, ERROR_MESSAGE1 + ", " + error, httpStatus);
     }
 
     public OnapCommandLoginFailed(Throwable throwable) {
-        this(throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE1, throwable);
     }
 }
 
 
     private static final long serialVersionUID = 1150649507734289032L;
     private static final String ERROR_CODE = "0x0010";
-    private static final String ERROR_MESSAGE1 = "Logout failed, ";
+    private static final String ERROR_MESSAGE1 = "Logout failed";
 
     public OnapCommandLogoutFailed(String error) {
-        super(ERROR_CODE, ERROR_MESSAGE1 + error);
+        super(ERROR_CODE, ERROR_MESSAGE1 +", " + error);
     }
 
     public OnapCommandLogoutFailed(Throwable throwable) {
-        this(throwable.getMessage());
+        super(ERROR_CODE, ERROR_MESSAGE1, throwable);
     }
 
     public OnapCommandLogoutFailed(int statusCode) {
 
 
     private static final long serialVersionUID = -1957064141442406239L;
 
+    private static final String ERROR_CODE = "0x0014";
+
+    private static final String ERROR_MSG = "Command is failed to print the result";
+
     public OnapCommandOutputPrintingFailed(String error) {
-        super("0x0014", "Command is failed to print the result, " + error);
+        super(ERROR_CODE,  ERROR_MSG + ", " + error);
     }
 
     public OnapCommandOutputPrintingFailed(Throwable throwable) {
-        this(throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG , throwable);
     }
 }
 
 
 package org.onap.cli.fw.error;
 
-import java.io.IOException;
-
 /**
  * Command profile persistence failed.
  *
 
     private static final long serialVersionUID = 8580121615330415123L;
 
+    private static final String ERROR_CODE = "0x1302";
+
+    private static final String ERROR_MSG = "Failed to persist profile details";
+
     /**
      * Command result empty.
      */
     public OnapCommandPersistProfileFailed(String error) {
-        super("0x1302", "Failed to persist profile details, " + error);
+        super(ERROR_CODE, ERROR_MSG + ", " + error);
     }
 
     public OnapCommandPersistProfileFailed(Throwable e1) {
-        this(e1.getMessage());
+        super(ERROR_CODE, ERROR_MSG, e1);
     }
 }
 
 
     private static final long serialVersionUID = 5513297861129088460L;
 
+    private static final String ERROR_CODE = "0x0018";
+
+    private static final String ERROR_MSG = "Failed to register the command ";
+
     public OnapCommandRegistrationFailed(String cmdName, String error) {
-        super("0x0018", "Command " + cmdName + " is failed to register, " + error);
+        super(ERROR_CODE,  ERROR_MSG + cmdName + ", " + error);
     }
 
     public OnapCommandRegistrationFailed(String cmdName, Throwable throwable) {
-        this(cmdName, throwable.getMessage());
+        super(ERROR_CODE,  ERROR_MSG + cmdName,  throwable);
     }
 }
 
 
     private static final long serialVersionUID = 8580121615330415123L;
 
+    private static final String ERROR_CODE = "0x0022";
+
+    private static final String ERROR_MSG = "Failed to parse the result format of command ";
+
     public OnapCommandResultInitialzationFailed(String cmd, String error) {
-        super("0x0022", "Command " + cmd + " result format is failed, " + error);
+        super(ERROR_CODE, ERROR_MSG + cmd + ", " + error);
     }
 
     public OnapCommandResultInitialzationFailed(String cmd, Throwable throwable) {
-        this(cmd, throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG + cmd , throwable);
     }
 }
 
 public class OnapCommandResultMapProcessingFailed extends OnapCommandException {
     private static final long serialVersionUID = 488775545436113019L;
 
-    private static final String errorCode = "0x0028";
+    private static final String ERROR_CODE = "0x0028";
+
+    private static final String ERROR_MSG = "Failed to parse the result format of command ";
 
     public OnapCommandResultMapProcessingFailed(String resultMap, String error) {
-        super(errorCode, "Failed to process the result map " + resultMap + " in http section,  " + error);
+        super(ERROR_CODE, ERROR_MSG + resultMap + ", " + error);
     }
 
     public OnapCommandResultMapProcessingFailed(String resultMap, Throwable throwable) {
-        this(resultMap, throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG + resultMap, throwable);
     }
 }
 
 
     private static final long serialVersionUID = -3919580583845280200L;
 
+    private static final String ERROR_CODE = "0x0019";
+
+    private static final String ERROR_MSG = "Command schema is missing for command ";
+
     public OnapCommandSchemaNotFound(String cmdName) {
-        this(cmdName, new Exception(""));
+        super(ERROR_CODE, ERROR_MSG + cmdName);
     }
 
     public OnapCommandSchemaNotFound(String cmdName, Throwable throwable) {
-        super("0x0019", "Command schema " + cmdName + " is not found, " + throwable.getMessage());
+        super(ERROR_CODE, ERROR_MSG + cmdName, throwable);
     }
 }
 
 cli.version=1.0
 cli.http.api_key_use_cookies=true
 cli.discover_always=false
+
 cli.service_name=onap-cli
 cli.api_gateway=msb
 cli.auth_service=auth
 
             registerar.get("Test2");
             fail("This should have thrown an exception");
         } catch (OnapCommandRegistrationFailed e) {
-            assertTrue(e.getMessage().contains("0x0018::Command Test2 is failed to register"));
+            assertEquals("0x0018", e.getErrorCode());
         }
     }
 
 
         OnapCommandDiscoveryFailed failed = new OnapCommandDiscoveryFailed("name");
         assertEquals("0x0010::Failed auto discover schema files from name under class path, ", failed.getMessage());
         failed = new OnapCommandDiscoveryFailed("directory", "name");
-        assertEquals("0x0010::Failed auto generate json file 'name' under class path directory 'directory' , ",
+        assertEquals("0x0010::Failed auto generate json file 'name' under class path directory 'directory'",
                 failed.getMessage());
     }
 
     @Test
     public void onapCommandResultMapProcessingFailedTest() {
         OnapCommandResultMapProcessingFailed failed = new OnapCommandResultMapProcessingFailed("name",
-                new Exception(""));
-        assertEquals("0x0028::Failed to process the result map name in http section,  ", failed.getMessage());
+                new Exception("failed"));
+        assertEquals("0x0028::Failed to parse the result format of command name, failed", failed.getMessage());
     }
 
     @Test
     public void onapCommandInvalidSchemaTest() {
         OnapCommandInvalidSchema failed = new OnapCommandInvalidSchema("Schema", "Failed");
 
-        assertEquals("0x0007::Command schema Schema is invalid, Failed", failed.getMessage());
+        assertEquals("0x0007::Invalid command schema Schema, Failed", failed.getMessage());
     }
 
     @Test
         assertEquals("0x0010::Logout failed, Failed", failed.getMessage());
 
         failed = new OnapCommandLogoutFailed(200);
-        assertEquals("200::0x0010::Logout failed, ", failed.getMessage());
+        assertEquals("200::0x0010::Logout failed", failed.getMessage());
     }
 
     @Test
     public void onapCommandRegistrationFailedTest() {
         OnapCommandRegistrationFailed failed = new OnapCommandRegistrationFailed("Test", "error");
 
-        assertEquals("0x0018::Command Test is failed to register, error", failed.getMessage());
+        assertEquals("0x0018::Failed to register the command Test, error", failed.getMessage());
     }
 
     @Test
         OnapCommandResultInitialzationFailed failed = new OnapCommandResultInitialzationFailed("Test",
                 new Exception("error"));
 
-        assertEquals("0x0022::Command Test result format is failed, error", failed.getMessage());
+        assertEquals("0x0022::Failed to parse the result format of command Test, error", failed.getMessage());
     }
 
     @Test
     public void onapCommandSchemaNotFoundTest() {
         OnapCommandSchemaNotFound failed = new OnapCommandSchemaNotFound("Test");
 
-        assertEquals("0x0019::Command schema Test is not found, ", failed.getMessage());
+        assertEquals("0x0019::Command schema is missing for command Test", failed.getMessage());
     }
 
     @Test
 
         try {
             OnapCommandUtils.loadSchema(cmd, "sample-test-schema.yaml");
         } catch (OnapCommandInvalidSchema e) {
-            assertTrue(e.getMessage().contains("0x0007::Command schema sample-test-schema.yaml is invalid"));
+            assertEquals("0x0007", e.getErrorCode());
         }
     }