Fix the incorrect package imports of the log4j grpc log appender. (#6385)

This commit is contained in:
Evan 2021-02-17 17:27:26 +08:00 committed by GitHub
parent badd05783a
commit ecd0213587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 130 additions and 8 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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,17 +54,49 @@
<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>
<artifactId>apm-toolkit-micrometer-registry</artifactId>
<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>

View File

@ -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();
}
}

View File

@ -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

View File

@ -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>

View File

@ -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);