You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/02/17 09:27:48 UTC

[skywalking] branch master updated: Fix the incorrect package imports of the log4j grpc log appender. (#6385)

This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new ecd0213  Fix the incorrect package imports of the log4j grpc log appender. (#6385)
ecd0213 is described below

commit ecd021358793d0b74aff483f1554dd3fec8dae69
Author: Evan <31...@users.noreply.github.com>
AuthorDate: Wed Feb 17 17:27:26 2021 +0800

    Fix the incorrect package imports of the log4j grpc log appender. (#6385)
---
 .../apm-toolkit-log4j-2.x-activation/pom.xml       |  4 +--
 .../apm-toolkit-logback-1.x-activation/pom.xml     |  3 +-
 test/e2e/e2e-service-provider/pom.xml              | 35 ++++++++++++++++++++++
 .../skywalking/e2e/controller/LogController.java   | 14 +++++++--
 .../src/main/resources/log4j.properties            | 16 ++++++++++
 .../src/main/resources/log4j2.xml                  | 34 +++++++++++++++++++++
 .../java/org/apache/skywalking/e2e/log/LogE2E.java | 32 ++++++++++++++++++--
 7 files changed, 130 insertions(+), 8 deletions(-)

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 73a1f46..f9a54ac 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 @@
   ~
   -->
 
-<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">
+<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">
     <parent>
         <artifactId>apm-toolkit-activation</artifactId>
         <groupId>org.apache.skywalking</groupId>
@@ -26,7 +27,6 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>apm-toolkit-log4j-2.x-activation</artifactId>
-
     <properties>
         <log4j-core.version>2.7</log4j-core.version>
     </properties>
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 67c8067..8057659 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 @@
   ~
   -->
 
-<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">
+<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">
     <parent>
         <artifactId>apm-toolkit-activation</artifactId>
         <groupId>org.apache.skywalking</groupId>
diff --git a/test/e2e/e2e-service-provider/pom.xml b/test/e2e/e2e-service-provider/pom.xml
index 11892c8..593a85e 100644
--- a/test/e2e/e2e-service-provider/pom.xml
+++ b/test/e2e/e2e-service-provider/pom.xml
@@ -35,6 +35,9 @@
 
     <properties>
         <sw.version>8.4.0</sw.version>
+        <log4j.version>1.2.17</log4j.version>
+        <log4j2.version>2.7</log4j2.version>
+        <logback.version>1.2.3</logback.version>
     </properties>
 
     <dependencies>
@@ -51,6 +54,12 @@
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
+            <exclusions>
+                <exclusion>
+                    <artifactId>log4j-to-slf4j</artifactId>
+                    <groupId>org.apache.logging.log4j</groupId>
+                </exclusion>
+            </exclusions>
         </dependency>
         <dependency>
             <groupId>org.apache.skywalking</groupId>
@@ -58,12 +67,38 @@
             <version>8.2.0</version>
         </dependency>
         <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>${log4j.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>log4j-core</artifactId>
+            <version>${log4j2.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>ch.qos.logback</groupId>
+            <artifactId>logback-classic</artifactId>
+            <version>${logback.version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.skywalking</groupId>
             <artifactId>apm-toolkit-logback-1.x</artifactId>
             <version>${sw.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.skywalking</groupId>
+            <artifactId>apm-toolkit-log4j-1.x</artifactId>
+            <version>${sw.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.skywalking</groupId>
+            <artifactId>apm-toolkit-log4j-2.x</artifactId>
+            <version>${sw.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.skywalking</groupId>
             <artifactId>apm-toolkit-trace</artifactId>
             <version>${sw.version}</version>
         </dependency>
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 baa1b23..a84d99b 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 0000000..914600b
--- /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 0000000..135b422
--- /dev/null
+++ b/test/e2e/e2e-service-provider/src/main/resources/log4j2.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<Configuration status="WARN">
+    <Appenders>
+        <Console name="Console" target="SYSTEM_OUT">
+            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
+        </Console>
+        <GRPCLogClientAppender name="grpc-log"/>
+    </Appenders>
+
+
+
+    <Loggers>
+        <Root level="info">
+            <AppenderRef ref="Console"/>
+            <AppenderRef ref="grpc-log"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ 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 2d57d07..a3ffb4d 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<Log> 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<Log> 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<Log> logs = graphql.logs(logsQuery);
         LOGGER.info("logs: {}", logs);