From ecd021358793d0b74aff483f1554dd3fec8dae69 Mon Sep 17 00:00:00 2001 From: Evan <31562192+EvanLjp@users.noreply.github.com> Date: Wed, 17 Feb 2021 17:27:26 +0800 Subject: [PATCH] Fix the incorrect package imports of the log4j grpc log appender. (#6385) --- .../apm-toolkit-log4j-2.x-activation/pom.xml | 4 +-- .../pom.xml | 3 +- test/e2e/e2e-service-provider/pom.xml | 35 +++++++++++++++++++ .../e2e/controller/LogController.java | 14 ++++++-- .../src/main/resources/log4j.properties | 16 +++++++++ .../src/main/resources/log4j2.xml | 34 ++++++++++++++++++ .../org/apache/skywalking/e2e/log/LogE2E.java | 32 +++++++++++++++-- 7 files changed, 130 insertions(+), 8 deletions(-) create mode 100644 test/e2e/e2e-service-provider/src/main/resources/log4j.properties create mode 100644 test/e2e/e2e-service-provider/src/main/resources/log4j2.xml diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/pom.xml index 73a1f4661..f9a54ac72 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/pom.xml +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-log4j-2.x-activation/pom.xml @@ -17,7 +17,8 @@ ~ --> - + apm-toolkit-activation org.apache.skywalking @@ -26,7 +27,6 @@ 4.0.0 apm-toolkit-log4j-2.x-activation - 2.7 diff --git a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/pom.xml b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/pom.xml index 67c806769..8057659ca 100644 --- a/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/pom.xml +++ b/apm-sniffer/apm-toolkit-activation/apm-toolkit-logback-1.x-activation/pom.xml @@ -17,7 +17,8 @@ ~ --> - + apm-toolkit-activation org.apache.skywalking diff --git a/test/e2e/e2e-service-provider/pom.xml b/test/e2e/e2e-service-provider/pom.xml index 11892c8c3..593a85eb0 100644 --- a/test/e2e/e2e-service-provider/pom.xml +++ b/test/e2e/e2e-service-provider/pom.xml @@ -35,6 +35,9 @@ 8.4.0 + 1.2.17 + 2.7 + 1.2.3 @@ -51,17 +54,49 @@ org.springframework.boot spring-boot-starter-actuator + + + log4j-to-slf4j + org.apache.logging.log4j + + org.apache.skywalking apm-toolkit-micrometer-registry 8.2.0 + + log4j + log4j + ${log4j.version} + + + org.apache.logging.log4j + log4j-core + ${log4j2.version} + provided + + + ch.qos.logback + logback-classic + ${logback.version} + org.apache.skywalking apm-toolkit-logback-1.x ${sw.version} + + org.apache.skywalking + apm-toolkit-log4j-1.x + ${sw.version} + + + org.apache.skywalking + apm-toolkit-log4j-2.x + ${sw.version} + org.apache.skywalking apm-toolkit-trace diff --git a/test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/controller/LogController.java b/test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/controller/LogController.java index baa1b2317..a84d99b04 100644 --- a/test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/controller/LogController.java +++ b/test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/controller/LogController.java @@ -17,18 +17,26 @@ package org.apache.skywalking.e2e.controller; -import lombok.extern.slf4j.Slf4j; +import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; import org.apache.skywalking.apm.toolkit.trace.TraceContext; +import org.slf4j.LoggerFactory; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -@Slf4j @RestController public class LogController { + private static final Logger LOG4J_LOGGER = Logger.getLogger(LogController.class); + private static final org.apache.logging.log4j.Logger LOG4J2_LOGGER = LogManager.getLogger( + LogController.class); + private static final org.slf4j.Logger LOGBACK_LOGGER = LoggerFactory.getLogger(LogController.class); + @RequestMapping(value = "/logs/trigger") public String trigger() { - LOGGER.info("now: {}", System.currentTimeMillis()); + LOG4J_LOGGER.info("log4j message==> now: " + System.currentTimeMillis()); + LOG4J2_LOGGER.info("log4j2 message==> now: " + System.currentTimeMillis()); + LOGBACK_LOGGER.info("logback message==> now: {}", System.currentTimeMillis()); return TraceContext.traceId(); } } diff --git a/test/e2e/e2e-service-provider/src/main/resources/log4j.properties b/test/e2e/e2e-service-provider/src/main/resources/log4j.properties new file mode 100644 index 000000000..914600b61 --- /dev/null +++ b/test/e2e/e2e-service-provider/src/main/resources/log4j.properties @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +log4j.rootLogger=info,CustomAppender +log4j.appender.CustomAppender=org.apache.skywalking.apm.toolkit.log.log4j.v1.x.log.GRPCLogClientAppender \ No newline at end of file diff --git a/test/e2e/e2e-service-provider/src/main/resources/log4j2.xml b/test/e2e/e2e-service-provider/src/main/resources/log4j2.xml new file mode 100644 index 000000000..135b422a2 --- /dev/null +++ b/test/e2e/e2e-service-provider/src/main/resources/log4j2.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/log/LogE2E.java b/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/log/LogE2E.java index 2d57d071e..a3ffb4d56 100644 --- a/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/log/LogE2E.java +++ b/test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/log/LogE2E.java @@ -89,12 +89,40 @@ public class LogE2E extends SkyWalkingTestAdapter { } @RetryableTest - public void verifyLog() throws Exception { + public void verifyLog4jLog() throws Exception { LogsQuery logsQuery = new LogsQuery().serviceId("WW91cl9BcHBsaWNhdGlvbk5hbWU=.1") .start(startTime) .end(Times.now()); if (graphql.supportQueryLogsByKeywords()) { - logsQuery.keywordsOfContent("now"); + logsQuery.keywordsOfContent("log4j message"); + } + final List logs = graphql.logs(logsQuery); + LOGGER.info("logs: {}", logs); + + load("expected/log/logs.yml").as(LogsMatcher.class).verifyLoosely(logs); + } + + @RetryableTest + public void verifyLog4j2Log() throws Exception { + LogsQuery logsQuery = new LogsQuery().serviceId("WW91cl9BcHBsaWNhdGlvbk5hbWU=.1") + .start(startTime) + .end(Times.now()); + if (graphql.supportQueryLogsByKeywords()) { + logsQuery.keywordsOfContent("log4j2 message"); + } + final List logs = graphql.logs(logsQuery); + LOGGER.info("logs: {}", logs); + + load("expected/log/logs.yml").as(LogsMatcher.class).verifyLoosely(logs); + } + + @RetryableTest + public void verifyLogbackLog() throws Exception { + LogsQuery logsQuery = new LogsQuery().serviceId("WW91cl9BcHBsaWNhdGlvbk5hbWU=.1") + .start(startTime) + .end(Times.now()); + if (graphql.supportQueryLogsByKeywords()) { + logsQuery.keywordsOfContent("logback message"); } final List logs = graphql.logs(logsQuery); LOGGER.info("logs: {}", logs);