Removed MsoLogger from SO 'common' module 90/79090/1
authorr.bogacki <r.bogacki@samsung.com>
Mon, 25 Feb 2019 09:23:33 +0000 (10:23 +0100)
committerr.bogacki <r.bogacki@samsung.com>
Mon, 25 Feb 2019 09:24:36 +0000 (10:24 +0100)
Replaced MsoLogger with plain slf4j.
Refactored login output.

Change-Id: I3ff1882406782d64cf0f572c574ab1068449f76b
Issue-ID: LOG-631
Signed-off-by: Robert Bogacki <r.bogacki@samsung.com>
common/src/main/java/org/onap/so/client/RestRequest.java
common/src/main/java/org/onap/so/logger/LoggerStartupListener.java
common/src/main/java/org/onap/so/openpojo/rules/HasAnnotationPropertyWithValueMatcher.java
common/src/main/java/org/onap/so/utils/CryptoUtils.java
common/src/main/java/org/onap/so/utils/UUIDChecker.java
common/src/main/java/org/onap/so/utils/XmlMarshaller.java
common/src/main/java/org/onap/so/web/exceptions/RuntimeExceptionMapper.java

index 4788acf..6f0d71c 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
@@ -26,13 +28,13 @@ import java.util.concurrent.Callable;
 import javax.ws.rs.NotFoundException;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 
-import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class RestRequest implements Callable<Response> {
 
-       private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, RestRequest.class);
+       private static final Logger logger = LoggerFactory.getLogger(RestRequest.class);
 
        private final RestClient client;
        private final String method;
@@ -73,7 +75,7 @@ public class RestRequest implements Callable<Response> {
                                mapper.get().map(response);
                        } catch (NotFoundException e) {
                                if (this.client.props.mapNotFoundToEmpty() && "GET".equals(method)) {
-                                       msoLogger.debug("RestClient recieved not found on URL: " + this.client.getWebTarget().getUri());
+                                       logger.debug("RestClient recieved not found on URL: {}", this.client.getWebTarget().getUri());
                                        return response;
                                } else {
                                        throw e;
index 794d02a..cd7859a 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
@@ -23,11 +25,11 @@ package org.onap.so.logger;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 
-import org.onap.so.utils.UUIDChecker;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.spi.LoggerContextListener;
 import ch.qos.logback.core.Context;
@@ -37,8 +39,8 @@ import ch.qos.logback.core.spi.LifeCycle;
 @Component
 public class LoggerStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {
 
-    private boolean started = false;
-    private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL, LoggerStartupListener.class);
+       private boolean started = false;
+       private static final Logger logger = LoggerFactory.getLogger(LoggerStartupListener.class);
 
     @Override
     public void start() {
@@ -48,7 +50,7 @@ public class LoggerStartupListener extends ContextAwareBase implements LoggerCon
                try {
                        addr = InetAddress.getLocalHost();
                } catch (UnknownHostException e) {
-                       LOGGER.error("UnknownHostException",e);
+                       logger.error("UnknownHostException",e);
                        
                }    
         Context context = getContext();
@@ -72,10 +74,6 @@ public class LoggerStartupListener extends ContextAwareBase implements LoggerCon
                return true;
        }
 
-       @Override
-       public void onLevelChange(Logger arg0, Level arg1) {
-       }
-
        @Override
        public void onReset(LoggerContext arg0) {
        }
@@ -87,4 +85,8 @@ public class LoggerStartupListener extends ContextAwareBase implements LoggerCon
        @Override
        public void onStop(LoggerContext arg0) {
        }
+
+       @Override
+       public void onLevelChange(ch.qos.logback.classic.Logger logger, Level level) {
+       }
 }
index 551305c..f76a27c 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
 package org.onap.so.openpojo.rules;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 import org.hamcrest.Description;
 import org.hamcrest.Matcher;
 import org.hamcrest.TypeSafeDiagnosingMatcher;
-import org.onap.so.logger.MsoLogger;
 
 import com.openpojo.reflection.PojoField;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class HasAnnotationPropertyWithValueMatcher<T extends PojoField> extends TypeSafeDiagnosingMatcher<T> {
-       private MsoLogger logger=MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, HasAnnotationPropertyWithValueMatcher.class);
+       private Logger logger = LoggerFactory.getLogger(HasAnnotationPropertyWithValueMatcher.class);
        private final String attribute;
        private final Matcher<?> annotationMatcher;
        private final Class<? extends Annotation> annotationClass;
index c35ced5..a109778 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
@@ -23,6 +25,8 @@ package org.onap.so.utils;
 
 import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.crypto.Cipher;
 import javax.crypto.spec.GCMParameterSpec;
@@ -38,7 +42,8 @@ import java.util.Arrays;
  */
 public final class CryptoUtils {
 
-    private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, CryptoUtils.class);
+    private static final Logger logger = LoggerFactory.getLogger(CryptoUtils.class);
+
 
     private static final String AES = "AES";
     private static final String CLOUD_KEY = "aa3871669d893c7fb8abbcda31b88b4f";
@@ -86,17 +91,19 @@ public final class CryptoUtils {
        try {
                return CryptoUtils.encrypt(message, CLOUD_KEY);
            } catch (GeneralSecurityException e) {
-               LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
-               return null;
-           }
+          logger.error("{} {} {}", MessageEnum.RA_GENERAL_EXCEPTION.toString(),
+              MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Exception in encryptPassword ", e);
+          return null;
+      }
     }
     public static String decryptCloudConfigPassword(String message) {
        try {
                return CryptoUtils.decrypt(message, CLOUD_KEY);
            } catch (GeneralSecurityException e) {
-               LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e);
-               return null;
-           }
+          logger.error("{} {} {}", MessageEnum.RA_GENERAL_EXCEPTION.toString(),
+              MsoLogger.ErrorCode.BusinessProcesssError.getValue(), "Exception in encryptPassword ", e);
+          return null;
+      }
     }
     private static SecretKeySpec getSecretKeySpec (String keyString) {
         byte[] key = hexStringToByteArray (keyString);
index fac73e8..36fa3d0 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
+ * Modifications Copyright (c) 2019 Samsung
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,12 +26,15 @@ import java.util.UUID;
 
 import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  */
 public class UUIDChecker {
-       
-       private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.GENERAL, UUIDChecker.class);
+
+    private static final Logger logger = LoggerFactory.getLogger(UUIDChecker.class);
+
 
     private UUIDChecker() {
 
@@ -44,7 +48,7 @@ public class UUIDChecker {
             UUID uuid = UUID.fromString(id);
             return uuid.toString().equalsIgnoreCase(id);
         } catch (IllegalArgumentException iae) {
-               LOGGER.debug("IllegalArgumentException", iae);
+            logger.debug("IllegalArgumentException", iae);
             return false;
         }
     }
index 903d055..864266b 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
@@ -35,12 +37,14 @@ import javax.xml.transform.sax.SAXSource;
 import org.onap.so.exceptions.MarshallerException;
 import org.onap.so.logger.MessageEnum;
 import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 
 public class XmlMarshaller {
 
-    private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, XmlMarshaller.class);
+    private static Logger logger = LoggerFactory.getLogger(XmlMarshaller.class);
 
     public static String marshal(Object object) throws MarshallerException {
 
@@ -50,7 +54,8 @@ public class XmlMarshaller {
             Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
             jaxbMarshaller.marshal(object, stringWriter);
         } catch (JAXBException e) {
-            logger.error(MessageEnum.GENERAL_EXCEPTION, "", "", "", MsoLogger.ErrorCode.SchemaError, e.getMessage(), e);
+            logger.error("{} {} {}", MessageEnum.GENERAL_EXCEPTION.toString(),
+                MsoLogger.ErrorCode.SchemaError.getValue(), e.getMessage(), e);
             throw new MarshallerException(e.getMessage(), MsoLogger.ErrorCode.SchemaError.getValue(), e);
         }
 
@@ -74,7 +79,8 @@ public class XmlMarshaller {
             SAXSource source = new SAXSource(xmlReader, inputSource);
             object = jaxbUnmarshaller.unmarshal(source, object.getClass()).getValue();
         } catch (Exception e) {
-            logger.error(MessageEnum.GENERAL_EXCEPTION, "", "", "", MsoLogger.ErrorCode.SchemaError, e.getMessage(), e);
+            logger.error("{} {} {}", MessageEnum.GENERAL_EXCEPTION.toString(),
+                MsoLogger.ErrorCode.SchemaError.getValue(), e.getMessage(), e);
             throw new MarshallerException(e.getMessage(), MsoLogger.ErrorCode.SchemaError.getValue(), e);
         }
 
index 9ddfd05..2c249f1 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed 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
@@ -26,11 +28,12 @@ import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.ext.ExceptionMapper;
 
 
-import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
 
-       private static MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, RuntimeExceptionMapper.class);
+       private static Logger logger = LoggerFactory.getLogger(RuntimeExceptionMapper.class);
 
        @Override
        public Response toResponse(RuntimeException exception) {
@@ -38,8 +41,7 @@ public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException>
                if (exception instanceof NotFoundException) {
                        return Response.status(Status.NOT_FOUND).build();
                } else {
-
-                       logger.error(exception);
+                       logger.error("Error occured", exception);
                        return Response.status(Status.INTERNAL_SERVER_ERROR).entity(new ExceptionResponse("Unexpected Internal Exception")).build();
                }
        }