diff options
author | noahs <noah.shogan@gmail.com> | 2017-12-06 13:11:38 +0200 |
---|---|---|
committer | noahs <noah.shogan@amdocs.com> | 2017-12-06 17:38:57 +0200 |
commit | f9f112f5fd5b193e79e38442cc566b7b437f87d2 (patch) | |
tree | 01a1ef7f840cbacb5ed465095926d14e83a7fd27 /openecomp-be/lib | |
parent | 0566f581c0f310384f42838c388f57234ed1d60e (diff) |
Duplicate logging frameworks merging
There was two copies of the SDC logging framework
Change-Id: I55c94c9817a83162c6d90e504dfd91e4858c7269
Issue-ID: SDC-703
Signed-off-by: noahs <noah.shogan@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
58 files changed, 2142 insertions, 539 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml index 5766fdfd4c..4472cfe477 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/pom.xml @@ -3,7 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.openecomp.sdc</groupId> <artifactId>openecomp-sdc-healing-core</artifactId> <parent> @@ -23,11 +22,6 @@ <artifactId>openecomp-sdc-validation-api</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>org.openecomp.sdc</groupId> - <artifactId>openecomp-sdc-vendor-software-product-api</artifactId> - <version>${project.version}</version> - </dependency> </dependencies> </project> diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml index d5e3e9e0b7..c54f724b9a 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/pom.xml @@ -18,6 +18,12 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.openecomp.sdc</groupId> <artifactId>openecomp-sdc-vendor-software-product-api</artifactId> <version>${project.version}</version> @@ -33,12 +39,6 @@ <artifactId>openecomp-sdc-vendor-license-api</artifactId> <version>${project.version}</version> </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>${junit.version}</version> - <scope>test</scope> - </dependency> </dependencies> diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java index 20ba5ebf19..da44ec422f 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/test/java/org/openecomp/sdc/healing/healers/util/TestUtil.java @@ -1,5 +1,6 @@ package org.openecomp.sdc.healing.healers.util; +import org.junit.Assert; import org.openecomp.core.utilities.json.JsonUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; @@ -7,7 +8,6 @@ import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.ToscaExtensionYamlUtil; import org.openecomp.sdc.tosca.services.ToscaUtil; -import org.springframework.util.Assert; import java.io.File; import java.io.FileInputStream; @@ -98,8 +98,7 @@ public class TestUtil { ServiceTemplate actualServiceTemplate = actualServiceTemplates.get(serviceTemplateName); - Assert.notNull(actualServiceTemplate, - "Missing service template in service model : " + serviceTemplateName); + Assert.assertNotNull("Missing service template in service model : " + serviceTemplateName, actualServiceTemplate); org.junit.Assert.assertEquals("Difference in file " + serviceTemplateName, JsonUtil.object2Json(expectedServiceTemplateEntry.getValue()), JsonUtil.object2Json(actualServiceTemplate)); diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml deleted file mode 100644 index 8623552aff..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <artifactId>openecomp-sdc-logging-api</artifactId> - <name>openecomp-sdc-logging-api</name> - - <parent> - <groupId>org.openecomp.sdc</groupId> - <artifactId>openecomp-logging-lib</artifactId> - <version>1.2.0-SNAPSHOT</version> - </parent> - - <dependencies> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.aspectj</groupId> - <artifactId>aspectjrt</artifactId> - <version>${aspectj.version}</version> - </dependency> - </dependencies> - - <!--dependencies> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>${spring.framework.version}</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.framework.version}</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.framework.version}</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>${spring.framework.version}</version> - </dependency> - </dependencies--> - - -</project> diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java deleted file mode 100644 index 049481141a..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Debug.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -package org.openecomp.sdc.logging.api.annotations; - -/** - * Created by TALIO on 12/26/2016. - */ - -public @interface Debug { - -} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml deleted file mode 100644 index 8eb22bda96..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/logback.xml +++ /dev/null @@ -1,284 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<configuration scan="true" scanPeriod="5 seconds"> - - <property scope="system" name="OPENECOMP-component-name" value="ASDC" /> - <property scope="system" name="OPENECOMP-subcomponent-name" value="ASDC-BE" /> - <property file="${config.home}/catalog-be/configuration.yaml" /> - <property scope="context" name="enable-all-log" value="false" /> - - <!--statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" /> - <include resource="asdc_debug_logback.xml"/--> - - <!-- value used by pattern field list (| - is inter-field separator, || - unavailable or not applicable field value) (m - mandatory, o- optional)--> - <!--timestamp(m)| requestID(m)| serviceInstanceID(o)| threadID(m)| physicalServerName(o)| serviceName(m)| userID(m)| logLevel(m)| severity(o)| serverIpAddress(m)| serverName(m)| clientIpAddress(o)| className(m)| timer(o)| detailedMessage(o)--> - <property name="default-log-pattern" - value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{uuid}|%X{serviceInstanceID}|%thread||${OPENECOMP-subcomponent-name}|%X{userId}|%level|%X{alarmSeverity}|%X{localAddr}|${beFqdn}|%X{remoteAddr}|%logger{35}|%X{timer}|ActivityType=<%M>, Desc=<%msg>%n" /> - - <property name="asdc-debug-log-pattern" value="%d{yyyy-MM-dd'T'HH:mm:ss.SSSXXX}|%X{RequestId}|%msg %n"/> - - <!-- All log --> - <if condition='property("enable-all-log").equalsIgnoreCase("true")'> - <then> - <appender name="ALL_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log - </file> - - <rollingPolicy - class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/all.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${default-log-pattern}</pattern> - </encoder> - </appender> - - <appender name="ASYNC_ALL" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="ALL_ROLLING" /> - </appender> - </then> - </if> - - <!-- Error log --> - <appender name="ERROR_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log - </file> - - <!-- Audit messages filter - deny audit messages --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>AUDIT_MARKER</marker> - </evaluator> - <onMismatch>NEUTRAL</onMismatch> - <onMatch>DENY</onMatch> - </filter> - - <!-- Transaction messages filter - deny Transaction messages --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>TRANSACTION_MARKER</marker> - </evaluator> - <onMismatch>NEUTRAL</onMismatch> - <onMatch>DENY</onMatch> - </filter> - - <!-- deny all events with a level below INFO, that is TRACE and DEBUG --> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> - <level>INFO</level> - </filter> - - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/Error.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${default-log-pattern}</pattern> - </encoder> - </appender> - - <!-- Debug log --> - <appender name="DEBUG_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log - </file> - - <!-- No need to deny audit messages - they are INFO only, will be denied - anyway --> - <!-- Transaction messages filter - deny Transaction messages, there are - some DEBUG level messages among them --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>TRANSACTION_MARKER</marker> - </evaluator> - <onMismatch>NEUTRAL</onMismatch> - <onMatch>DENY</onMatch> - </filter> - - <!-- accept DEBUG and TRACE level --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator"> - <expression> - e.level.toInt() <= DEBUG.toInt() - </expression> - </evaluator> - <OnMismatch>DENY</OnMismatch> - <OnMatch>NEUTRAL</OnMatch> - </filter> - - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${default-log-pattern}</pattern> - </encoder> - </appender> - - <!-- Debug log --> - <appender name="PACKAGE_DEBUG_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log - </file> - - <!-- No need to deny audit messages - they are INFO only, will be denied - anyway --> - <!-- Transaction messages filter - deny Transaction messages, there are - some DEBUG level messages among them --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>TRANSACTION_MARKER</marker> - </evaluator> - <onMismatch>NEUTRAL</onMismatch> - <onMatch>DENY</onMatch> - </filter> - - <!-- accept DEBUG and TRACE level --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator"> - <expression> - e.level.toInt() <= DEBUG.toInt() - </expression> - </evaluator> - <OnMismatch>DENY</OnMismatch> - <OnMatch>NEUTRAL</OnMatch> - </filter> - - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/debug_by_package.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${asdc-debug-log-pattern}</pattern> - </encoder> - </appender> - - <!-- Audit log --> - <appender name="AUDIT_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log - </file> - - <!-- Audit messages filter - accept audit messages --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>AUDIT_MARKER</marker> - </evaluator> - <onMismatch>DENY</onMismatch> - <onMatch>ACCEPT</onMatch> - </filter> - - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/audit.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${default-log-pattern}</pattern> - </encoder> - </appender> - - <!-- SdncTransaction log --> - <appender name="TRANSACTION_ROLLING" - class="ch.qos.logback.core.rolling.RollingFileAppender"> - - <file>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log - </file> - - <!-- Transaction messages filter - accept audit messages --> - <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> - <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> - <marker>TRANSACTION_MARKER</marker> - </evaluator> - <onMismatch>DENY</onMismatch> - <onMatch>ACCEPT</onMatch> - </filter> - - <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> - <fileNamePattern>${log.home}/${OPENECOMP-component-name}/${OPENECOMP-subcomponent-name}/transaction.log.%i - </fileNamePattern> - <minIndex>1</minIndex> - <maxIndex>10</maxIndex> - </rollingPolicy> - - <triggeringPolicy - class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> - <maxFileSize>20MB</maxFileSize> - </triggeringPolicy> - <encoder> - <pattern>${default-log-pattern}</pattern> - </encoder> - </appender> - - <!-- Asynchronicity Configurations --> - <appender name="ASYNC_DEBUG" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="DEBUG_ROLLING" /> - </appender> - - <appender name="ASYNC_TRANSACTION" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="TRANSACTION_ROLLING" /> - </appender> - - <appender name="ASYNC_ERROR" class="ch.qos.logback.classic.AsyncAppender"> - <appender-ref ref="ERROR_ROLLING" /> - </appender> - - - <root level="INFO"> - <appender-ref ref="ASYNC_ERROR" /> - <appender-ref ref="ASYNC_DEBUG" /> - <appender-ref ref="AUDIT_ROLLING" /> - <appender-ref ref="ASYNC_TRANSACTION" /> - <if condition='property("enable-all-log").equalsIgnoreCase("true")'> - <then> - <appender-ref ref="ALL_ROLLING" /> - </then> - </if> - </root> - - <logger name="org.openecomp.sdc" level="INFO" /> - - <logger name="org.openecomp.sdc.vendorsoftwareproduct" level="DEBUG" additivity ="false"> - <appender-ref ref="PACKAGE_DEBUG_ROLLING" /> - </logger> - - <logger name="org.openecomp.sdc.vendorlicense" level="DEBUG" additivity ="false"> - <appender-ref ref="PACKAGE_DEBUG_ROLLING" /> - </logger> -</configuration>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml deleted file mode 100644 index be8e5521a3..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <name>openecomp-sdc-logging-core</name> - <groupId>org.openecomp.sdc</groupId> - <artifactId>openecomp-sdc-logging-core</artifactId> - - <parent> - <groupId>org.openecomp.sdc</groupId> - <artifactId>openecomp-logging-lib</artifactId> - <version>1.2.0-SNAPSHOT</version> - </parent> - - <dependencies> - <dependency> - <groupId>org.openecomp.sdc</groupId> - <artifactId>openecomp-sdc-logging-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>${spring.framework.version}</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-webmvc</artifactId> - <version>${spring.framework.version}</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>ch.qos.logback</groupId> - <artifactId>logback-classic</artifactId> - <version>${logback.version}</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>${servlet.version}</version> - </dependency> - </dependencies> - -</project> diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java b/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java deleted file mode 100644 index 7ac5be0591..0000000000 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/DebugAspect.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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========================================================= - */ - -package org.openecomp.sdc.logging.aspects; - -import org.aspectj.lang.JoinPoint; -import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; - -import java.lang.reflect.Method; - - -/** - * Created by TALIO on 12/26/2016. - */ -public class DebugAspect { - - private static final String MESSAGE_TEMPLATE = "'{}' '{}' with '{}'"; - private static final Marker DEBUG = MarkerFactory.getMarker("DEBUG"); - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - -// @Autowired -// private ParameterNameDiscoverer parameterNameDiscoverer; - - public void debugEnterMethod(final JoinPoint joinPoint){ - - Class type = joinPoint.getSignature().getDeclaringType(); - Method currentMethod = null; - for(Method method : type.getMethods()){ - if(method.getName().equals(joinPoint.getSignature().getName())){ - currentMethod = method; - break; - } - } - -// String[] parameterNames = parameterNameDiscoverer.getParameterNames(currentMethod); -// Object[] args = joinPoint.getArgs(); -// Parameter[] parameters = currentMethod.getParameters(); -// StringBuilder str = new StringBuilder(joinPoint.getSignature().getName() + " with parameters:" + -// " "); -// if(args.length == parameters.length) { -// for (int i = 0; i < args.length; i++) { -// str.append(parameters[i].getName()).append('=').append(args[i]); -// } -// } - mdcDataDebugMessage.debugEntryMessage(null, null); - } - - public void debugExitMethod(final JoinPoint joinPoint){ - mdcDataDebugMessage.debugExitMessage(null, null); - } -} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml new file mode 100644 index 0000000000..3158995cb8 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/pom.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <artifactId>openecomp-sdc-logging-api</artifactId> + <name>openecomp-sdc-logging-api</name> + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-logging-lib</artifactId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>${slf4j-api.version}</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>${slf4j.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>${testng.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java index 3be67dfde2..918818adb0 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/BaseFactory.java @@ -37,7 +37,7 @@ import java.util.ServiceLoader; */ public class BaseFactory { - protected static <T> T locateService(Class<T> clazz) throws Exception { + protected static <T> T locateService(Class<T> clazz) { T service; ServiceLoader<T> loader = ServiceLoader.load(clazz); diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java index 9055e64f8b..9055e64f8b 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/Logger.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java index fbad636412..fbad636412 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerCreationService.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java index 68365fd857..68365fd857 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/LoggerFactory.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java index 2bcad91e38..2bcad91e38 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/annotations/Metrics.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java index 98200da337..98200da337 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/ContextPropagationService.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java index e2b31c3202..e2b31c3202 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/api/context/TaskFactory.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java index a6a673d9dc..a6a673d9dc 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/context/MdcData.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java index d562ae5dd8..d562ae5dd8 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/AuditMessages.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java index c3e5f977cc..c3e5f977cc 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/messages/DebugMessages.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java index 71884cff70..71884cff70 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/DebugConstants.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java index 0d591be095..0d591be095 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerConstants.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java index 5addccde7d..e00c282b97 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCategory.java @@ -26,5 +26,5 @@ public enum LoggerErrorCategory { WARN, DEBUG, INFO, - FATAL; + FATAL } diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java index 3f48991c7f..3f48991c7f 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorCode.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java index 7e502d55f2..7e502d55f2 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerErrorDescription.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java index e72d66aac9..e72d66aac9 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerServiceName.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java index 6b0570eb29..6b0570eb29 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/types/LoggerTragetServiceName.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json index 33163b32bb..33163b32bb 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/resources/factoryConfiguration.json diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java new file mode 100644 index 0000000000..846425059e --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/LoggerFactoryTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging.api; + +import org.testng.annotations.Test; + +import java.lang.reflect.Field; +import java.util.ServiceLoader; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 14/09/2016. + */ +public class LoggerFactoryTest { + + @Test + public void testNoOpLoggerService() throws Exception { + + assertFalse(ServiceLoader.load(LoggerCreationService.class).iterator().hasNext()); + + LoggerFactory.getLogger(LoggerFactoryTest.class); + Field factory = LoggerFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object impl = factory.get(null); + assertEquals("org.openecomp.sdc.logging.api.LoggerFactory$NoOpLoggerCreationService", + impl.getClass().getName()); + } + + @Test + public void testNoOpLoggerByClass() throws Exception { + Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class); + verifyLogger(logger); + } + + @Test + public void testNoOpLoggerByName() throws Exception { + Logger logger = LoggerFactory.getLogger(LoggerFactoryTest.class.getName()); + verifyLogger(logger); + } + + private void verifyLogger(Logger logger) { + assertNotNull(logger); + + // make sure no exceptions are thrown + logger.error(""); + logger.warn(""); + logger.info(""); + logger.debug(""); + logger.audit(""); + logger.metrics(""); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java new file mode 100644 index 0000000000..61e1819b3b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/test/java/org/openecomp/sdc/logging/api/context/TaskFactoryTest.java @@ -0,0 +1,30 @@ +package org.openecomp.sdc.logging.api.context; + +import org.testng.annotations.Test; + +import java.util.ServiceLoader; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 14/09/2016. + */ +public class TaskFactoryTest { + + @Test(expectedExceptions = RuntimeException.class) + public void testNoImplementation() throws Exception { + + assertFalse(ServiceLoader.load(ContextPropagationService.class).iterator().hasNext()); + + try { + TaskFactory.create(() -> { + }); + } catch (RuntimeException e) { + Throwable cause = e.getCause(); + assertNotNull(cause); + assertTrue(cause.getMessage().contains(ContextPropagationService.class.getName())); + throw e; + } + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README new file mode 100644 index 0000000000..779c5d99df --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/README @@ -0,0 +1,29 @@ +The purpose of this module is to make a Web application meet the OPENECOMP logging requirements described in +OPENECOMP platform application logging guidelines. + +The default out-of-the box solution is based on SLF4J. + +It introduces three major areas of functionality as follows: + +1. Routing of logging messages for the Logback library, so that all logging events are written to separate files +according to their type. + +2. An AOP aspect for measuring execution time and logging it, so that the application code is not contaminated with +this type of logging. + +3. Collecting and populating the context of a Web API request and propagating it to every logging event. + +TODO: + +1. MetricsAspect + - Configurable metrics message + - Make sure there are no exceptions but applicative ones + +2. EventTypeDiscriminator + - Make event types configurable to make the names of log files easily customizable + +3. DispatchingAppender + - Read appenders from configuration, so that there is no need in EELF loggers + - Simpler use of discriminator or an entirely different mechanism + - Better appender name pattern, or mapping between a discriminating value and an appender name + - Discard the appenders cache on configuration changes diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml new file mode 100644 index 0000000000..e9e66b2fe2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/pom.xml @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <name>openecomp-sdc-logging-core</name> + <artifactId>openecomp-sdc-logging-core</artifactId> + + <parent> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-logging-lib</artifactId> + <version>1.2.0-SNAPSHOT</version> + </parent> + + <dependencies> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-logging-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.aspectj</groupId> + <artifactId>aspectjrt</artifactId> + <version>${aspectj.version}</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback.version}</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>${servlet.version}</version> + </dependency> + + <!-- for testing --> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>${testng.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.easymock</groupId> + <artifactId>easymock</artifactId> + <version>${easymock.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-easymock</artifactId> + <version>${powermock.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-core</artifactId> + <version>${powermock.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-testng</artifactId> + <version>${powermock.version}</version> + <scope>test</scope> + </dependency> + </dependencies> + +</project> diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java index 711e6d1559..711e6d1559 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/Markers.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java index 5b7ed5ef4d..7f9ada142a 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/SLF4JLoggerCreationService.java @@ -32,23 +32,23 @@ public class SLF4JLoggerCreationService implements LoggerCreationService { @Override public Logger getLogger(String className) { - return new SFL4JWrapper(className); + return new SLF4JWrapper(className); } @Override public Logger getLogger(Class<?> clazz) { - return new SFL4JWrapper(clazz); + return new SLF4JWrapper(clazz); } - private class SFL4JWrapper implements Logger { + private class SLF4JWrapper implements Logger { private final org.slf4j.Logger logger; - public SFL4JWrapper(Class<?> clazz) { + SLF4JWrapper(Class<?> clazz) { logger = LoggerFactory.getLogger(clazz); } - public SFL4JWrapper(String className) { + SLF4JWrapper(String className) { logger = LoggerFactory.getLogger(className); } diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java index 782362b912..2b46802a2e 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/aspects/MetricsAspect.java @@ -20,13 +20,12 @@ package org.openecomp.sdc.logging.aspects; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.slf4j.Marker; -import org.slf4j.MarkerFactory; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.api.annotations.Metrics; /** * <p>Wraps around any method annotated with {@link Metrics} to measure and log its execution time @@ -45,14 +44,13 @@ import org.slf4j.MarkerFactory; public class MetricsAspect { private static final String MESSAGE_TEMPLATE = "'{}' took {} milliseconds"; - private static final Marker METRICS = MarkerFactory.getMarker("METRICS"); @Around("@annotation(org.openecomp.sdc.logging.api.annotations.Metrics)") public Object logExecutionTime(ProceedingJoinPoint pjp) throws Throwable { final Logger logger = LoggerFactory.getLogger(pjp.getSignature().getDeclaringTypeName()); // measure and log only if the logger for this class is enabled - if (logger.isInfoEnabled()) { + if (logger.isMetricsEnabled()) { final String method = pjp.getSignature().getName(); final long start = System.currentTimeMillis(); @@ -60,7 +58,7 @@ public class MetricsAspect { try { return pjp.proceed(); } finally { - logger.info(METRICS, MESSAGE_TEMPLATE, method, System.currentTimeMillis() - start); + logger.metrics(MESSAGE_TEMPLATE, method, System.currentTimeMillis() - start); } } else { diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java index 7e29f3c093..7e29f3c093 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MDCPropagationService.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java index 24d47162f4..81a22adb07 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/MdcUtil.java @@ -23,8 +23,6 @@ package org.openecomp.sdc.logging.context; import org.openecomp.sdc.logging.types.LoggerConstants; import org.slf4j.MDC; -import java.util.UUID; - public class MdcUtil { diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java index b21504d752..11d3fd3f5b 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataDebugMessage.java @@ -70,10 +70,10 @@ public class MdcDataDebugMessage extends MdcData { logDebugMessage(entityParameter, DebugConstants.EXIT, ids); } - public void logDebugMessage(String entityParameter, String enterOrExit, String... ids) { + private void logDebugMessage(String entityParameter, String enterOrExit, String... ids) { String methodName = LoggingUtils.getCallingMethodNameForDebugging(); String declaringClass = LoggingUtils.getDeclaringClass(); - logger = (Logger) LoggerFactory.getLogger(declaringClass); + logger = LoggerFactory.getLogger(declaringClass); String messageToWrite; if (entityParameter == null || ids == null) { diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java index 190c37d2b6..190c37d2b6 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/context/impl/MdcDataErrorMessage.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java index 2273e1c7ef..2273e1c7ef 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/DispatchingAppender.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java index 5aa36656af..5aa36656af 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminator.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java index 31b89464c9..7294b9b5d6 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/servlet/LoggingFilter.java @@ -20,7 +20,6 @@ package org.openecomp.sdc.logging.servlet; -import org.omg.CORBA.Request; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.slf4j.MDC; @@ -63,7 +62,7 @@ public class LoggingFilter implements Filter { private static final HostAddressCache HOST_ADDRESS = new HostAddressCache(); private static final String UNKNOWN = "UNKNOWN"; - private final static Logger log = (Logger) LoggerFactory.getLogger(LoggingFilter.class.getName()); + private final static Logger LOGGER = LoggerFactory.getLogger(LoggingFilter.class); public void destroy() { } @@ -118,7 +117,7 @@ public class LoggingFilter implements Filter { private static final long REFRESH_TIME = 1000L; - private AtomicLong lastUpdated = new AtomicLong(0L); + private final AtomicLong lastUpdated = new AtomicLong(0L); private InetAddress hostAddress; public InetAddress get() { @@ -132,7 +131,7 @@ public class LoggingFilter implements Filter { lastUpdated.set(current); // set now to register the attempt even if failed hostAddress = InetAddress.getLocalHost(); } catch (UnknownHostException e) { - log.debug("",e); + LOGGER.error("Failed to retrieve local hostname for logging", e); hostAddress = null; } } diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java index 06b0d5b2bc..06b0d5b2bc 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/util/LoggingUtils.java diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService index ee01c4d871..ee01c4d871 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.LoggerCreationService diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService index 2c401614ae..2c401614ae 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/main/resources/META-INF/services/org.openecomp.sdc.logging.api.context.ContextPropagationService diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java new file mode 100644 index 0000000000..fe81a4626a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/LoggerFactoryTest.java @@ -0,0 +1,25 @@ +package org.openecomp.sdc.logging; + +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; + +import static org.testng.Assert.assertEquals; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class LoggerFactoryTest { + + @Test + public void testCreate() throws Exception { + // test that the service loader loads the right implementation + LoggerFactory.getLogger(LoggerFactoryTest.class); + Field factory = LoggerFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object implementation = factory.get(null); + assertEquals(SLF4JLoggerCreationService.class, implementation.getClass()); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java new file mode 100644 index 0000000000..87f2f17ba0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/RoutingTest.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.sift.SiftingAppender; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; +import org.openecomp.sdc.logging.logback.EventTypeDiscriminator; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Predicate; + +/** + * TODO: Add more negative tests + * + * @author EVITALIY + * @since 17/08/2016. + */ +public class RoutingTest { + + private static final String ERROR = "Error"; + private static final String DEBUG = "Debug"; + private static final String AUDIT = "Audit"; + private static final String METRICS = "Metrics"; + + private Logger logger; + private Map<String, TestAppender> result = new ConcurrentHashMap<>(); + + @BeforeClass + public void setUp() { + + SiftingAppender appender = new SiftingAppender(); + + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + discriminator.start(); + + appender.setDiscriminator(discriminator); + appender.setAppenderFactory((context, discriminatingValue) -> + result.computeIfAbsent(discriminatingValue, f -> { + TestAppender tmp = new TestAppender(); + tmp.start(); + return tmp; + })); + + appender.start(); + + logger = (Logger) LoggerFactory.getLogger(RoutingTest.class.getName()); + // prevent from writing into appenders attached via parent loggers + logger.setAdditive(false); + logger.addAppender(appender); + logger.setLevel(Level.DEBUG); + } + + @Test + public void testWarning() { + String msg = "This is a test warning"; + logger.warn(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.WARN.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testError() { + String msg = "This is a test error"; + logger.error(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.ERROR.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testDebug() { + String msg = "This is a test debug"; + logger.debug(msg); + TestAppender appender = result.get(DEBUG); + Assert.assertTrue(appender.contains((event) -> + Level.DEBUG.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testInfo() { + String msg = "This is a test info"; + logger.info(msg); + TestAppender appender = result.get(ERROR); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testAudit() { + String msg = "This is a test audit"; + logger.info(Markers.AUDIT, msg); + TestAppender appender = result.get(AUDIT); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + @Test + public void testMetrics() { + String msg = "This is a test metrics"; + logger.info(Markers.METRICS, msg); + TestAppender appender = result.get(METRICS); + Assert.assertTrue(appender.contains((event) -> + Level.INFO.equals(event.getLevel()) && msg.equals(event.getFormattedMessage()))); + } + + /** + * An appender that just accumulates messages in a list and enables to inspect them + * + * @author EVITALIY + * @since 17/08/2016. + */ + private static class TestAppender extends AppenderBase<ILoggingEvent> { + + private List<ILoggingEvent> events = Collections.synchronizedList(new ArrayList<>(10)); + + @Override + protected void append(ILoggingEvent event) { + this.events.add(event); + } + + public boolean contains(Predicate<ILoggingEvent> predicate) { + return events.stream().anyMatch(predicate); + } + } +} diff --git a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java index 87184455c3..a191c80a98 100644 --- a/openecomp-be/lib/openecomp-logging-lib/openecomp-sdc-logging-core/src/main/java/org/openecomp/sdc/logging/method/LoggingInvocationHandler.java +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/api/LoggerTest.java @@ -18,28 +18,48 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.sdc.logging.method; +package org.openecomp.sdc.logging.api; -import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; +import org.testng.annotations.Test; /** - * Created by TALIO on 1/8/2017. + * This is only for manual testing - change ENABLE to 'true' + * + * @author evitaliy + * @since 13/09/2016. */ -public class LoggingInvocationHandler implements InvocationHandler { +public class LoggerTest { + + private static final boolean ENABLED = false; + private static final Logger LOGGER = LoggerFactory.getLogger(LoggerTest.class); - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); - private final Object invocImpl; + @Test(enabled = ENABLED) + public void testMetrics() throws Exception { + LOGGER.metrics("This is metrics"); + } + + @Test(enabled = ENABLED) + public void testAudit() throws Exception { + LOGGER.audit("This is audit"); + } + + @Test(enabled = ENABLED) + public void testDebug() throws Exception { + LOGGER.debug("This is debug"); + } + + @Test(enabled = ENABLED) + public void testInfo() throws Exception { + LOGGER.info("This is info"); + } - public LoggingInvocationHandler(final Object invocImpl){ - this.invocImpl = invocImpl; + @Test(enabled = ENABLED) + public void testWarn() throws Exception { + LOGGER.warn("This is warning"); } - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - mdcDataDebugMessage.debugEntryMessage(null, null); - return method.invoke(invocImpl, args); + @Test(enabled = ENABLED) + public void testError() throws Exception { + LOGGER.error("This is error"); } } diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java new file mode 100644 index 0000000000..8b9ee3ee08 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/aspects/MetricsAspectTest.java @@ -0,0 +1,451 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging.aspects; + +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.Signature; +import org.aspectj.lang.reflect.SourceLocation; +import org.aspectj.runtime.internal.AroundClosure; +import org.easymock.EasyMock; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.powermock.api.easymock.PowerMock; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.testng.PowerMockTestCase; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; + +/** + * @author EVITALIY + * @since 17/08/2016. + */ +@PrepareForTest(LoggerFactory.class) +public class MetricsAspectTest extends PowerMockTestCase { + + private static final Object OBJ_TO_RETURN = new Object(); + private static final String EXPECTED_MESSAGE = "'{}' took {} milliseconds"; + + @Test + public void testLogExecutionTime() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + TestLogger logger = initLogging(className, true); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPoint(className, methodName); + Object returned = aspect.logExecutionTime(pjp); + + Assert.assertEquals(OBJ_TO_RETURN, returned); + assertExecution(methodName, pjp, logger); + } + + @Test + public void testMetricsDisabled() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + TestLogger logger = initLogging(className, false); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPoint(className, methodName); + Object returned = aspect.logExecutionTime(pjp); + + Assert.assertEquals(OBJ_TO_RETURN, returned); + Assert.assertEquals(1, pjp.getCount()); + // return any event - must be empty + Assert.assertFalse(logger.contains((event) -> true)); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testThrowingError() throws Throwable { + + String className = UUID.randomUUID().toString(); + String methodName = UUID.randomUUID().toString(); + + final TestLogger logger = initLogging(className, true); + + MetricsAspect aspect = new MetricsAspect(); + MockProceedingJoinPoint pjp = new MockProceedingJoinPointWithException(className, methodName); + + try { + aspect.logExecutionTime(pjp); + } finally { + assertExecution(methodName, pjp, logger); + } + } + + private TestLogger initLogging(String className, boolean enabled) { + TestLogger logger = new TestLogger(enabled); + PowerMock.mockStatic(LoggerFactory.class); + EasyMock.expect(LoggerFactory.getLogger(className)).andReturn(logger); + PowerMock.replay(LoggerFactory.class); + return logger; + } + + private void assertExecution(String methodName, MockProceedingJoinPoint pjp, TestLogger logger) { + + Assert.assertEquals(1, pjp.getCount()); + Assert.assertTrue(logger.contains((event) -> + (event != null) && (event.length == 3) && EXPECTED_MESSAGE.equals(event[0]) + && methodName.equals(event[1]) && (event[2] instanceof Long))); + } + + private static class MockSignature implements Signature { + + private final String className; + private final String methodName; + + private MockSignature(String className, String methodName) { + this.className = className; + this.methodName = methodName; + } + + @Override + public String toShortString() { + return null; + } + + @Override + public String toLongString() { + return null; + } + + @Override + public String getName() { + return methodName; + } + + @Override + public int getModifiers() { + return 0; + } + + @Override + public Class getDeclaringType() { + return null; + } + + @Override + public String getDeclaringTypeName() { + return className; + } + } + + private static class MockProceedingJoinPoint implements ProceedingJoinPoint { + + private AtomicInteger count = new AtomicInteger(0); + private Signature signature; + + MockProceedingJoinPoint(String className, String methodName) { + this.signature = new MockSignature(className, methodName); + } + + int getCount() { + return count.get(); + } + + @Override + public Object proceed() throws Throwable { + count.incrementAndGet(); + return OBJ_TO_RETURN; + } + + @Override + public void set$AroundClosure(AroundClosure aroundClosure) { + + } + + @Override + public Object proceed(Object[] objects) throws Throwable { + return null; + } + + @Override + public String toShortString() { + return null; + } + + @Override + public String toLongString() { + return null; + } + + @Override + public Object getThis() { + return null; + } + + @Override + public Object getTarget() { + return null; + } + + @Override + public Object[] getArgs() { + return new Object[0]; + } + + @Override + public Signature getSignature() { + return this.signature; + } + + @Override + public SourceLocation getSourceLocation() { + return null; + } + + @Override + public String getKind() { + return null; + } + + @Override + public StaticPart getStaticPart() { + return null; + } + } + + private static class MockProceedingJoinPointWithException extends MockProceedingJoinPoint { + + MockProceedingJoinPointWithException(String className, String methodName) { + super(className, methodName); + } + + @Override + public Object proceed() throws Throwable { + super.proceed(); + throw new IllegalArgumentException(); + } + } + + private class TestLogger implements Logger { + + private final boolean enabled; + private List<Object[]> events = Collections.synchronizedList(new ArrayList<>(10)); + + TestLogger(boolean enabled) { + this.enabled = enabled; + } + + @Override + public String getName() { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isMetricsEnabled() { + return this.enabled; + } + + @Override + public void metrics(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Object var2, Object var3) { + + if (this.enabled) { + events.add(new Object[]{var1, var2, var3}); + } + } + + @Override + public void metrics(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void metrics(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isAuditEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void audit(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isDebugEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void debug(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isInfoEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void info(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isWarnEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void warn(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + @Override + public boolean isErrorEnabled() { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object var2, Object var3) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Object... var2) { + throw new RuntimeException("Not implemented"); + } + + @Override + public void error(String var1, Throwable throwable) { + throw new RuntimeException("Not implemented"); + } + + public boolean contains(Predicate<Object[]> predicate) { + return events.stream().anyMatch(predicate); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java new file mode 100644 index 0000000000..c0aa1d018a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/MDCPropagationFactoryTest.java @@ -0,0 +1,223 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging.context; + +import org.slf4j.MDC; +import org.testng.annotations.Test; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.testng.Assert.*; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class MDCPropagationFactoryTest { + + // Disable if an old version of MDC implementation is being used. + // MDCPropagationFactory should be used when MDC is not propagated to child threads. + // See https://jira.qos.ch/browse/LOGBACK-422 and https://jira.qos.ch/browse/LOGBACK-624 + private static final boolean ENABLED = false; + + @Test(enabled = ENABLED) + public void testNoPropagation() throws InterruptedException { + + String uuid = UUID.randomUUID().toString(); + AtomicBoolean complete = new AtomicBoolean(false); + MDC.put("data", uuid); + + Runnable runnable = () -> { + assertNull(MDC.get("data"), "Data unexpectedly copied to a child thread. " + + "Are you using an old version of MDC implementation (e.g. logback)?"); + complete.set(true); + }; + + Thread thread = new Thread(runnable); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), uuid, "Expected data to be retained in this thread"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testPropagation() throws InterruptedException { + + String uuid = UUID.randomUUID().toString(); + AtomicBoolean complete = new AtomicBoolean(false); + MDC.put("data", uuid); + + MDCPropagationService factory = new MDCPropagationService(); + Runnable runnable = factory.create(() -> { + assertEquals(MDC.get("data"), uuid, "Expected data to be propagated to the child thread's MDC"); + complete.set(true); + }); + + Thread thread = new Thread(runnable); + thread.start(); + + thread.join(); + + assertEquals(MDC.get("data"), uuid, "Expected data to be retained in this thread"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testReplacement() throws InterruptedException { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + String outerUuid = UUID.randomUUID().toString(); + MDC.put("data", outerUuid); + inner.run(); + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be replaced with stored data"); + outerComplete.set(true); + }; + + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected data to be retained in this thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testEmpty() throws InterruptedException { + + final AtomicBoolean complete = new AtomicBoolean(false); + + MDC.remove("data"); + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + + MDCPropagationService factory = new MDCPropagationService(); + Runnable runnable = factory.create(() -> { + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + complete.set(true); + }); + + Thread thread = new Thread(runnable); + thread.start(); + thread.join(); + + assertNull(MDC.get("data"), "Expected MDC data to be empty"); + assertTrue(complete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testCleanup() throws Exception { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + assertNull(MDC.get("data"), "Expected MDC data not to be copied to this thread"); + inner.run(); + assertNull(MDC.get("data"), "Expected MDC data to remain empty in this thread"); + outerComplete.set(true); + }; + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected MDC data to be retained in parent thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + } + + @Test(enabled = ENABLED) + public void testCleanupAfterError() throws Exception { + + String innerUuid = UUID.randomUUID().toString(); + AtomicBoolean innerComplete = new AtomicBoolean(false); + AtomicBoolean outerComplete = new AtomicBoolean(false); + AtomicBoolean exceptionThrown = new AtomicBoolean(false); + + MDC.put("data", innerUuid); + + MDCPropagationService factory = new MDCPropagationService(); + + // should run with the context of main thread + Runnable inner = factory.create(() -> { + assertEquals(MDC.get("data"), innerUuid, "Expected data to be propagated to the child thread's MDC"); + innerComplete.set(true); + throw new RuntimeException(); + }); + + // pushes its own context, but runs the inner runnable + Runnable outer = () -> { + + String outerUuid = UUID.randomUUID().toString(); + MDC.put("data", outerUuid); + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be populated in this thread"); + + try { + inner.run(); + } catch (RuntimeException e) { + exceptionThrown.set(true); + } finally { + assertEquals(MDC.get("data"), outerUuid, "Expected MDC data to be reverted even in case of exception"); + outerComplete.set(true); + } + }; + + Thread thread = new Thread(outer); + thread.start(); + thread.join(); + + assertEquals(MDC.get("data"), innerUuid, "Expected MDC data to be retained in parent thread"); + assertTrue(outerComplete.get(), "Expected the outer thread to run"); + assertTrue(innerComplete.get(), "Expected the inner thread to run"); + assertTrue(exceptionThrown.get(), "Expected the inner class to throw exception"); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java new file mode 100644 index 0000000000..dad60d44d5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/context/TaskFactoryTest.java @@ -0,0 +1,26 @@ +package org.openecomp.sdc.logging.context; + +import org.openecomp.sdc.logging.api.context.TaskFactory; +import org.testng.annotations.Test; + +import java.lang.reflect.Field; + +import static org.testng.Assert.assertEquals; + +/** + * @author evitaliy + * @since 12/09/2016. + */ +public class TaskFactoryTest { + + @Test + public void testCreate() throws Exception { + // test that the service loader loads the right implementation + TaskFactory.create(() -> { + }); + Field factory = TaskFactory.class.getDeclaredField("SERVICE"); + factory.setAccessible(true); + Object implementation = factory.get(null); + assertEquals(MDCPropagationService.class, implementation.getClass()); + } +}
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java new file mode 100644 index 0000000000..39b3170a5b --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/logback/EventTypeDiscriminatorTest.java @@ -0,0 +1,220 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging.logback; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.LoggingEvent; +import org.openecomp.sdc.logging.Markers; +import org.slf4j.MarkerFactory; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +/** + * @author EVITALIY + * @since 17/08/2016. + */ +public class EventTypeDiscriminatorTest { + + private static final String DEBUG = "Debug"; + private static final String ERROR = "Error"; + + @Test + public void testGetDefaultDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetInfoDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetTraceDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetErrorWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetDebugWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetDebugWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithMetricsDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetErrorWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetWarnWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetDebugWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetTraceWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.TRACE); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), DEBUG); + } + + @Test + public void testGetInfoWithMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(MarkerFactory.getMarker("Dummy")); + assertEquals(discriminator.getDiscriminatingValue(event), ERROR); + } + + @Test + public void testGetAuditDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(Markers.AUDIT); + assertEquals(discriminator.getDiscriminatingValue(event), "Audit"); + } + + @Test + public void testGetMetricsMarkerDiscriminatingValue() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMarker(Markers.METRICS); + assertEquals(discriminator.getDiscriminatingValue(event), "Metrics"); + } + + @Test + public void testGetKey() throws Exception { + EventTypeDiscriminator discriminator = new EventTypeDiscriminator(); + assertEquals("eventType", discriminator.getKey()); + } + +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java new file mode 100644 index 0000000000..0779e38055 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/java/org/openecomp/sdc/logging/servlet/LoggingFilterTest.java @@ -0,0 +1,314 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +package org.openecomp.sdc.logging.servlet; + +import org.slf4j.MDC; +import org.testng.Assert; +import org.testng.annotations.Test; + +import javax.servlet.*; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.InetAddress; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; + +/** + * TODO: Add more tests + * + * @author EVITALIY + * @since 17/08/2016. + */ +public class LoggingFilterTest { + + private static final String REMOTE_HOST = UUID.randomUUID().toString(); + + @Test + public void testDoFilter() throws Exception { + LoggingFilter loggingFilter = new LoggingFilter(); + ServletRequest mockRequest = new TestServletRequest(); + ServletResponse mockResponse = new TestServletResponse(); + TestFilterChain mockChain = new TestFilterChain(); + loggingFilter.doFilter(mockRequest, mockResponse, mockChain); + assertEquals(1, mockChain.getCount()); + assertNull(MDC.getCopyOfContextMap()); + } + + private static class TestServletRequest implements ServletRequest { + + @Override + public Object getAttribute(String s) { + return null; + } + + @Override + public Enumeration getAttributeNames() { + return null; + } + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public void setCharacterEncoding(String s) throws UnsupportedEncodingException { + + } + + @Override + public int getContentLength() { + return 0; + } + + @Override + public String getContentType() { + return null; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + return null; + } + + @Override + public String getParameter(String s) { + return null; + } + + @Override + public Enumeration getParameterNames() { + return null; + } + + @Override + public String[] getParameterValues(String s) { + return new String[0]; + } + + @Override + public Map getParameterMap() { + return null; + } + + @Override + public String getProtocol() { + return null; + } + + @Override + public String getScheme() { + return null; + } + + @Override + public String getServerName() { + return null; + } + + @Override + public int getServerPort() { + return 0; + } + + @Override + public BufferedReader getReader() throws IOException { + return null; + } + + @Override + public String getRemoteAddr() { + return null; + } + + @Override + public String getRemoteHost() { + return REMOTE_HOST; + } + + @Override + public void setAttribute(String s, Object o) { + + } + + @Override + public void removeAttribute(String s) { + + } + + @Override + public Locale getLocale() { + return null; + } + + @Override + public Enumeration getLocales() { + return null; + } + + @Override + public boolean isSecure() { + return false; + } + + @Override + public RequestDispatcher getRequestDispatcher(String s) { + return null; + } + + @Override + public String getRealPath(String s) { + return null; + } + + @Override + public int getRemotePort() { + return 0; + } + + @Override + public String getLocalName() { + return null; + } + + @Override + public String getLocalAddr() { + return null; + } + + @Override + public int getLocalPort() { + return 0; + } + } + + private static class TestFilterChain implements FilterChain { + + private AtomicInteger count = new AtomicInteger(0); + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse) + throws IOException, ServletException { + + Assert.assertNotNull(MDC.get("RequestId")); + Assert.assertEquals(MDC.get("ServiceInstanceId"), "N/A"); + Assert.assertEquals(MDC.get("ServiceName"), "ASDC"); + Assert.assertEquals(MDC.get("InstanceUUID"), "N/A"); + Assert.assertEquals(MDC.get("RemoteHost"), REMOTE_HOST); + + InetAddress host = InetAddress.getLocalHost(); + Assert.assertEquals(MDC.get("ServerIPAddress"), host.getHostAddress()); + Assert.assertEquals(MDC.get("ServerFQDN"), host.getHostName()); + + count.incrementAndGet(); + } + + public int getCount() { + return count.get(); + } + } + + private static class TestServletResponse implements ServletResponse { + + @Override + public String getCharacterEncoding() { + return null; + } + + @Override + public void setCharacterEncoding(String s) { + + } + + @Override + public String getContentType() { + return null; + } + + @Override + public void setContentType(String s) { + + } + + @Override + public ServletOutputStream getOutputStream() throws IOException { + return null; + } + + @Override + public PrintWriter getWriter() throws IOException { + return null; + } + + @Override + public void setContentLength(int i) { + + } + + @Override + public int getBufferSize() { + return 0; + } + + @Override + public void setBufferSize(int i) { + + } + + @Override + public void flushBuffer() throws IOException { + + } + + @Override + public void resetBuffer() { + + } + + @Override + public boolean isCommitted() { + return false; + } + + @Override + public void reset() { + + } + + @Override + public Locale getLocale() { + return null; + } + + @Override + public void setLocale(Locale locale) { + + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README new file mode 100644 index 0000000000..430f36d760 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/README @@ -0,0 +1,8 @@ +Different routing/dispatching mechanisms can be tested using -Dlogback.configurationFile and a custom configuration +file, for example + +-Dlogback.configurationFile=<path>/dispatching-logback.xml + +or + +-Dlogback.configurationFile=<path>/sifting-logback.xml
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml new file mode 100644 index 0000000000..c6c51f14c1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/dispatching-logback.xml @@ -0,0 +1,335 @@ +<configuration scan="true" scanPeriod="3 seconds"> + <!--<jmxConfigurator /> --> + <!-- directory path for all other type logs --> + <property name="logDir" value="logs" /> + + <!-- directory path for debugging type logs --> + <property name="debugDir" value="debug-logs" /> + + <!-- specify the component name --> + <property name="componentName" value="SDC" /> + + <!-- log file names --> + <property name="generalLogName" value="application" /> + <property name="securityLogName" value="security" /> + <property name="performanceLogName" value="performance" /> + <property name="serverLogName" value="server" /> + <property name="policyLogName" value="policy" /> + <property name="errorLogName" value="error" /> + <property name="metricsLogName" value="metrics" /> + <property name="auditLogName" value="audit" /> + <property name="debugLogName" value="debug" /> + + <property name="defaultPattern" value="%date{ISO8601,UTC}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Timer}| %msg%n" /> + + <property name="debugLoggerPattern" value="%date{ISO8601,UTC}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Timer}|[%caller{3}]| %msg%n" /> + + <property name="logDirectory" value="${logDir}/${componentName}" /> + <property name="debugLogDirectory" value="${debugDir}/${componentName}" /> + + + <!-- Example evaluator filter applied against console appender --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <!-- ============================================================================ --> + <!-- EELF Appenders --> + <!-- ============================================================================ --> + + <!-- The EELFAppender is used to record events to the general application + log --> + + + <appender name="EELF" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${generalLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${generalLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELF" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELF" /> + </appender> + + <!-- EELF Security Appender. This appender is used to record security events + to the security log file. Security events are separate from other loggers + in EELF so that security log records can be captured and managed in a secure + way separate from the other logs. This appender is set to never discard any + events. --> + <appender name="EELFSecurity" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${securityLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${securityLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFSecurity" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <discardingThreshold>0</discardingThreshold> + <appender-ref ref="EELFSecurity" /> + </appender> + + <!-- EELF Performance Appender. This appender is used to record performance + records. --> + <appender name="EELFPerformance" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${performanceLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${performanceLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <outputPatternAsHeader>true</outputPatternAsHeader> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + <appender name="asyncEELFPerformance" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFPerformance" /> + </appender> + + <!-- EELF Server Appender. This appender is used to record Server related + logging events. The Server logger and appender are specializations of the + EELF application root logger and appender. This can be used to segregate Server + events from other components, or it can be eliminated to record these events + as part of the application root log. --> + <appender name="EELFServer" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${serverLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${serverLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + <appender name="asyncEELFServer" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFServer" /> + </appender> + + + <!-- EELF Policy Appender. This appender is used to record Policy engine + related logging events. The Policy logger and appender are specializations + of the EELF application root logger and appender. This can be used to segregate + Policy engine events from other components, or it can be eliminated to record + these events as part of the application root log. --> + <appender name="EELFPolicy" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${policyLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${policyLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + <appender name="asyncEELFPolicy" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFPolicy" /> + </appender> + + + <!-- EELF Audit Appender. This appender is used to record audit engine + related logging events. The audit logger and appender are specializations + of the EELF application root logger and appender. This can be used to segregate + Policy engine events from other components, or it can be eliminated to record + these events as part of the application root log. --> + + <appender name="EELFAudit" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${auditLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + <appender name="asyncEELFAudit" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFAudit" /> + </appender> + +<appender name="EELFMetrics" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${metricsLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${metricsLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + + <appender name="asyncEELFMetrics" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFMetrics"/> + </appender> + + <appender name="EELFError" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${errorLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFError"/> + </appender> + + <appender name="EELFDebug" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${debugLogDirectory}/${debugLogName}.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${debugLogDirectory}/${debugLogName}.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${debugLoggerPattern}</pattern> + </encoder> + </appender> + + <appender name="asyncEELFDebug" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="EELFDebug" /> + <includeCallerData>true</includeCallerData> + </appender> + + + <!-- ============================================================================ --> + <!-- EELF loggers --> + <!-- ============================================================================ --> + <logger name="org.openecomp.eelf" level="info" additivity="false"> + <appender-ref ref="asyncEELF" /> + </logger> + <logger name="org.openecomp.eelf.security" level="info" additivity="false"> + <appender-ref ref="asyncEELFSecurity" /> + </logger> + <logger name="org.openecomp.eelf.perf" level="info" additivity="false"> + <appender-ref ref="asyncEELFPerformance" /> + </logger> + <logger name="org.openecomp.eelf.server" level="info" additivity="false"> + <appender-ref ref="asyncEELFServer" /> + </logger> + <logger name="org.openecomp.eelf.policy" level="info" additivity="false"> + <appender-ref ref="asyncEELFPolicy" /> + </logger> + + <logger name="org.openecomp.eelf.audit" level="info" additivity="false"> + <appender-ref ref="asyncEELFAudit" /> + </logger> + + <logger name="org.openecomp.eelf.metrics" level="info" additivity="false"> + <appender-ref ref="asyncEELFMetrics" /> + </logger> + + + <logger name="org.openecomp.eelf.error" level="error" additivity="false"> + <appender-ref ref="asyncEELFError" /> + </logger> + + <logger name="org.openecomp.eelf.debug" level="debug" additivity="false"> + <appender-ref ref="asyncEELFDebug" /> + </logger> + + <appender name="DISPATCHER" class="org.openecomp.sdc.logging.logback.DispatchingAppender"> + <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/> + <appenderNamePattern>asyncEELF%s</appenderNamePattern> + </appender> + + <root level="DEBUG" additivity="false"> + <appender-ref ref="DISPATCHER" /> + </root> + +</configuration>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..4029db2215 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/logback-test.xml @@ -0,0 +1,41 @@ +<configuration scan="true" scanPeriod="3 seconds"> + + <property name="logDir" value="logs" /> + <property name="componentName" value="SDC" /> + + <property name="defaultPattern" + value="%logger|%date{ISO8601,UTC}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Timer}| %msg%n" /> + + <property name="logDirectory" value="${logDir}/${componentName}" /> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="DISPATCHER" class="ch.qos.logback.classic.sift.SiftingAppender"> + <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/> + <sift> + <appender name="${eventType}" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${eventType}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${eventType}.%i.log.zip</fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + </sift> + </appender> + + <root level="DEBUG"> + <appender-ref ref="DISPATCHER" /> + </root> + +</configuration>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml new file mode 100644 index 0000000000..b713b54b75 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-core/src/test/resources/sifting-logback.xml @@ -0,0 +1,42 @@ +<configuration scan="true" scanPeriod="3 seconds" debug="true"> + + <property name="logDir" value="logs" /> + <property name="componentName" value="SDC" /> + + <property name="defaultPattern" value="%date{ISO8601,UTC}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Timer}| %msg%n" /> + + <property name="debugPattern" value="%date{ISO8601,UTC}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{VirtualServerName}|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{ClassName}|%X{Timer}|[%caller{3}]| %msg%n" /> + + <property name="logDirectory" value="${logDir}/${componentName}" /> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + + <appender name="DISPATCHER" class="ch.qos.logback.classic.sift.SiftingAppender"> + <discriminator class="org.openecomp.sdc.logging.logback.EventTypeDiscriminator"/> + <sift> + <appender name="${eventType}" class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/${eventType}.log</file> + <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/${eventType}.%i.log.zip</fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <pattern>${defaultPattern}</pattern> + </encoder> + </appender> + </sift> + </appender> + + <root level="DEBUG" additivity="false"> + <appender-ref ref="DISPATCHER" /> + </root> + +</configuration>
\ No newline at end of file diff --git a/openecomp-be/lib/openecomp-logging-lib/pom.xml b/openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml index ffc91b8d89..589b8bbdbc 100644 --- a/openecomp-be/lib/openecomp-logging-lib/pom.xml +++ b/openecomp-be/lib/openecomp-sdc-logging-lib/pom.xml @@ -4,22 +4,19 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <groupId>org.openecomp.sdc</groupId> - <name>openecomp-logging-lib</name> - <artifactId>openecomp-logging-lib</artifactId> + <name>openecomp-sdc-logging-lib</name> + <artifactId>openecomp-sdc-logging-lib</artifactId> <packaging>pom</packaging> <parent> <groupId>org.openecomp.sdc</groupId> <artifactId>openecomp-sdc-lib</artifactId> <version>1.2.0-SNAPSHOT</version> - <relativePath>..</relativePath> </parent> <modules> - <module>/openecomp-sdc-logging-api</module> - <module>/openecomp-sdc-logging-core</module> + <module>openecomp-sdc-logging-api</module> + <module>openecomp-sdc-logging-core</module> </modules> - </project> diff --git a/openecomp-be/lib/pom.xml b/openecomp-be/lib/pom.xml index 868d0c6353..ea1faaec4b 100644 --- a/openecomp-be/lib/pom.xml +++ b/openecomp-be/lib/pom.xml @@ -28,7 +28,7 @@ <module>openecomp-tosca-lib</module> <module>openecomp-sdc-action-lib</module> <module>openecomp-sdc-enrichment-lib</module> - <module>openecomp-logging-lib</module> + <module>openecomp-sdc-logging-lib</module> <module>openecomp-healing-lib</module> <module>openecomp-sdc-activity-log-lib</module> <module>openecomp-tosca-converter-lib</module> |