diff options
author | Pooja03 <pm00501616@techmahindra.com> | 2018-11-29 16:18:26 +0530 |
---|---|---|
committer | Pooja03 <pm00501616@techmahindra.com> | 2018-11-29 16:18:26 +0530 |
commit | 78a858f5e83cdefe579bb880ab73d45adff502d2 (patch) | |
tree | 5668354cbc60e4314eaaca094c597dd609652e12 /snmpmapper | |
parent | 4a8d434d9082f7c3eeeafa2fef2aa70223a64db3 (diff) |
Logging Compliance as per ONAP
Logging compliance done as per ONAP
Issue-ID: DCAEGEN2-997
Change-Id: Ida19d8ed69d4e662ae632bf4456348a229c7e2e5
Signed-off-by: Pooja03 <pm00501616@techmahindra.com>
Diffstat (limited to 'snmpmapper')
5 files changed, 105 insertions, 78 deletions
diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java index f3234bb..1fdba15 100644 --- a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java +++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/DAO/MappingFileDAOImpl.java @@ -40,7 +40,9 @@ import org.springframework.web.multipart.MultipartFile; */ @Repository public class MappingFileDAOImpl implements MappingFileDAO { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); @Value("${spring.datasource.url}") String url; @@ -53,16 +55,16 @@ public class MappingFileDAOImpl implements MappingFileDAO { private static Map<String, String> env; @Override public String uploadMappingFile(MultipartFile mappingFile, String enterpriseid) throws SQLException, IOException { - + metricsLogger.info("Uploading mapping file"); env = System.getenv(); for (Map.Entry<String, String> entry : env.entrySet()) { - LOGGER.info(entry.getKey() + ":" + entry.getValue()); + debugLogger.info(entry.getKey() + ":" + entry.getValue()); } if (env.containsKey("CONSUL_HOST") && env.containsKey("CONFIG_BINDING_SERVICE") && env.containsKey("HOSTNAME")) { //TODO - Add logic to talk to Consul and CBS to get the configuration. For now, we will refer to configuration coming from docker env parameters - LOGGER.info(">>>Dynamic configuration to be used"); + debugLogger.info(">>>Dynamic configuration to be used"); if( (env.get("MR_DMAAPHOST")==null || (env.get("MR_DMAAPHOST")==null || @@ -72,8 +74,8 @@ public class MappingFileDAOImpl implements MappingFileDAO { (env.get("JDBC_PASSWORD")==null ))))))) { - LOGGER.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env URL_JDBC=jdbc:postgresql://10.53.172.129:5432/dummy --env JDBC_USERNAME=ngpuser --env JDBC_PASSWORD=root --env MR_DMAAPHOST=10.10.10.10 --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-collectors-ves --env CONFIG_BINDING_SERVICE=config_binding_service -e DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest"); - System.exit(SpringApplication.exit(applicationContext, () -> {LOGGER.error("Application is stoped please provide the above environment parameter during docker run");return-1;})); + errorLogger.error("Some docker environment parameter is missing. Sample Usage is -\n sudo docker run -d -p 8085:8085/tcp --env URL_JDBC=jdbc:postgresql://10.53.172.129:5432/dummy --env JDBC_USERNAME=ngpuser --env JDBC_PASSWORD=root --env MR_DMAAPHOST=10.10.10.10 --env MR_DEFAULT_PORT_NUMBER=3904 --env CONSUL_HOST=10.53.172.109 --env HOSTNAME=mvp-dcaegen2-collectors-ves --env CONFIG_BINDING_SERVICE=config_binding_service -e DMAAPHOST='10.53.172.156' onap/org.onap.dcaegen2.services.mapper.vesadapter.universalvesadaptor:latest"); + System.exit(SpringApplication.exit(applicationContext, () -> {errorLogger.error("Application is stoped please provide the above environment parameter during docker run");return-1;})); }else { @@ -83,7 +85,7 @@ public class MappingFileDAOImpl implements MappingFileDAO { } } else { - LOGGER.info(">>>Static configuration to be used"); + debugLogger.info(">>>Static configuration to be used"); } @@ -91,7 +93,7 @@ public class MappingFileDAOImpl implements MappingFileDAO { try (Connection con = DriverManager.getConnection(url, user, pwd); PreparedStatement pstmt = con.prepareStatement( "INSERT INTO mapping_file(enterpriseid, mappingfilecontents, mimetype, File_Name) VALUES (?, ?, ?, ?)")) { - LOGGER.debug("Connection established successfully"); + metricsLogger.info("Connection established successfully"); pstmt.setString(1, enterpriseid); pstmt.setBytes(2, mappingFile.getBytes()); @@ -101,7 +103,7 @@ public class MappingFileDAOImpl implements MappingFileDAO { pstmt.executeUpdate(); }catch (Exception e) { - LOGGER.error("Error occured due to :" + e.getMessage()); + errorLogger.error("Error occured due to :{}" , e.getMessage()); throw e; } return "Uploaded successfully"; diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java index 25ec834..cd25191 100644 --- a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java +++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/SnmpmapperApplication.java @@ -19,13 +19,16 @@ */ package org.onap.dcaegen2.services.mapper.snmpmapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SnmpmapperApplication { - + private static final Logger metricsLogger = LoggerFactory.getLogger("metricsLogger"); public static void main(String[] args) { + metricsLogger.info("Snmp Mapper main Startup"); SpringApplication.run(SnmpmapperApplication.class, args); } } diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java index 23398be..dc9eabb 100644 --- a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java +++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/controller/SnmpmapperController.java @@ -35,6 +35,8 @@ import javax.servlet.http.HttpServletRequest; import org.apache.catalina.startup.ClassLoaderFactory.Repository; import org.onap.dcaegen2.services.mapper.snmpmapper.entity.MappingFile; import org.onap.dcaegen2.services.mapper.snmpmapper.service.MappingFileService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; @@ -50,6 +52,7 @@ import org.springframework.web.servlet.ModelAndView; @Controller public class SnmpmapperController { + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); @Autowired MappingFileService mappingFileService; @@ -71,6 +74,7 @@ public class SnmpmapperController { @RequestMapping(value = "uploadFile", method = RequestMethod.POST) public String saveUploadedFileInDatabase(HttpServletRequest request, final @RequestParam MultipartFile[] mapper){ String result=mappingFileService.saveUploadedFileInDatabase(request, mapper); + debugLogger.debug("result of the mapping file upload:{}",result); if(result.equals("success")) { return "success.html"; }else diff --git a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java index b0e8821..bf7d0e5 100644 --- a/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java +++ b/snmpmapper/src/main/java/org/onap/dcaegen2/services/mapper/snmpmapper/service/MappingFileServiceImpl.java @@ -35,8 +35,8 @@ import org.springframework.web.multipart.MultipartFile; @Service public class MappingFileServiceImpl implements MappingFileService { - private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); - + private static final Logger debugLogger = LoggerFactory.getLogger("debugLogger"); + private static final Logger errorLogger = LoggerFactory.getLogger("errorLogger"); static String enterpriseid; static MappingFile mapping; @@ -49,7 +49,7 @@ public class MappingFileServiceImpl implements MappingFileService { // Reading File Upload Form Input Parameters enterpriseid = request.getParameter("eid"); - LOGGER.debug("EnterPrise ID recieved:{}",enterpriseid); + debugLogger.info("EnterPrise ID recieved:{}",enterpriseid); if ((mappingfile != null) && (mappingfile.length > 0)) { @@ -57,7 +57,7 @@ public class MappingFileServiceImpl implements MappingFileService { if(aFile.isEmpty()) { continue; } else { - LOGGER.debug("MappingFile Name = {} with enterprise id:{}", aFile.getOriginalFilename(),enterpriseid); + debugLogger.debug("MappingFile Name = {} with enterprise id:{}", aFile.getOriginalFilename(),enterpriseid); if (!aFile.getOriginalFilename().equals("")) { try { mapping = new MappingFile(); @@ -72,18 +72,18 @@ public class MappingFileServiceImpl implements MappingFileService { mappingFileDAO.uploadMappingFile(aFile,enterpriseid); } catch (SnmpMapperException snmpMapperException) { - LOGGER.error(snmpMapperException.getMessage()); + errorLogger.error(snmpMapperException.getMessage()); } catch (IOException e) { - LOGGER.error("IOException occured:{}",e.getCause()); + errorLogger.error("IOException occured:{}",e.getCause()); return "failed"; } catch (SQLException e) { - LOGGER.error("SQLException occured:{}",e.getCause()); + errorLogger.error("SQLException occured:{}",e.getCause()); return "failed"; } } } - LOGGER.debug("File Is Successfully Uploaded & Saved In The Database\n"); + debugLogger.info("File Is Successfully Uploaded & Saved In The Database\n"); } } else { return "failed"; diff --git a/snmpmapper/src/main/resources/logback.xml b/snmpmapper/src/main/resources/logback.xml index e979ca2..94ea189 100644 --- a/snmpmapper/src/main/resources/logback.xml +++ b/snmpmapper/src/main/resources/logback.xml @@ -1,79 +1,97 @@ <?xml version="1.0" encoding="UTF-8"?> -<configuration> +<!-- /* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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 +* +* 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. +* ============LICENSE_END========================================================= +*/ --> - <property name="DEV_HOME" value="logs" /> +<configuration scan="true" scanPeriod="30 seconds"> - <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <layout class="ch.qos.logback.classic.PatternLayout"> + <Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</Pattern> + </layout> + </appender> + + <property name="LOG_DIR" value="logs" /> + + <appender name="metricsAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/metrics.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> + <!-- rollover daily --> + <fileNamePattern>${LOG_DIR}/metrics-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> + </rollingPolicy> <layout class="ch.qos.logback.classic.PatternLayout"> - <Pattern> - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - </Pattern> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|UNKNOWN|%thread||snmpmapper||||COMPLETE|0|OK||%-5level||||||||||||||%class{36}:%M:%L: %m%n</pattern> </layout> </appender> - - <appender name="FILE-AUDIT" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${DEV_HOME}/debug.log</file> - <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> - <Pattern> - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - </Pattern> - </encoder> - - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + + <appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/debug.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!-- rollover daily --> - <fileNamePattern>${DEV_HOME}/archived/debug.%d{yyyy-MM-dd}.%i.log - </fileNamePattern> - <timeBasedFileNamingAndTriggeringPolicy - class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> - <maxFileSize>10MB</maxFileSize> - </timeBasedFileNamingAndTriggeringPolicy> + <fileNamePattern>${LOG_DIR}/debug-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> </rollingPolicy> - + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|%-5level:%class{36}:%M:%L: %m%n</pattern> + </layout> </appender> - - <appender name="FILE-ERROR" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <filter class="ch.qos.logback.classic.filter.LevelFilter"> - <level>ERROR</level> - <onMatch>ACCEPT</onMatch> - <onMismatch>DENY</onMismatch> - </filter> - <file>${DEV_HOME}/error.log</file> - <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> - <Pattern> - %d{yyyy-MM-dd HH:mm:ss} %logger{36} - %msg%n - </Pattern> - </encoder> - - <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> + + <appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${LOG_DIR}/error.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!-- rollover daily --> - <fileNamePattern>${DEV_HOME}/archived/error.%d{yyyy-MM-dd}.%i.log - </fileNamePattern> - <timeBasedFileNamingAndTriggeringPolicy - class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> - <maxFileSize>10MB</maxFileSize> - </timeBasedFileNamingAndTriggeringPolicy> + <fileNamePattern>${LOG_DIR}/error-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern> + <!-- each file should be at most 100MB, keep 2 days worth of history, but at most 200MB --> + <maxFileSize>100MB</maxFileSize> + <maxHistory>2</maxHistory> + <totalSizeCap>200MB</totalSizeCap> </rollingPolicy> - + <layout class="ch.qos.logback.classic.PatternLayout"> + <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSS+00:00}|NULL|%thread|snmpmapper||||ERROR|0|ERROR:|%class{36}:%M:%L: %m%n</pattern> + </layout> </appender> - <!-- Send logs to both console and file audit --> - <logger name="org.onap.dcaegen2.services.mapper.snmpmapper" level="debug" additivity="false"> - <appender-ref ref="FILE-AUDIT" /> - <appender-ref ref="STDOUT" /> + <logger name="metricsLogger" level="info" additivity="false"> + <appender-ref ref="metricsAppender" /> </logger> - <logger name="org.onap.dcaegen2.services.mapper.snmpmapper" level="debug" additivity="false"> - <appender-ref ref="FILE-AUDIT" /> - <appender-ref ref="FILE-ERROR" /> - <appender-ref ref="STDOUT" /> - </logger> - - <!-- <logger name="org.onap.universalvesadapter.adapter" level="error" additivity="false"> - <appender-ref ref="FILE-ERROR" /> - </logger> --> + <logger name="debugLogger" level="debug" additivity="false"> + <appender-ref ref="debugAppender" /> + </logger> + + <logger name="errorLogger" level="debug" additivity="false"> + <appender-ref ref="errorAppender" /> + <appender-ref ref="STDOUT" /> + </logger> + <!--<logger name="com" level="INFO"/> --> + <root level="info"> + <!-- <appender-ref ref="STDOUT" /> --> + <appender-ref ref="debugAppender" /> + </root> - </configuration>
\ No newline at end of file |