You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/02/10 10:58:31 UTC
[shardingsphere] branch master updated: Refactor log of test engine (#15342)
This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 89c51a9 Refactor log of test engine (#15342)
89c51a9 is described below
commit 89c51a9c2e339e2d89629119a0cea710198f51f8
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Thu Feb 10 18:57:39 2022 +0800
Refactor log of test engine (#15342)
---
.../container/atomic/ShardingSphereContainers.java | 6 +-
.../framework/container/logging/ContainerLogs.java | 69 ----------------------
2 files changed, 4 insertions(+), 71 deletions(-)
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/ShardingSphereContainers.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/ShardingSphereContainers.java
index 34d4ce8..4279402 100644
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/ShardingSphereContainers.java
+++ b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/atomic/ShardingSphereContainers.java
@@ -19,8 +19,9 @@ package org.apache.shardingsphere.test.integration.framework.container.atomic;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.test.integration.framework.container.logging.ContainerLogs;
+import org.slf4j.LoggerFactory;
import org.testcontainers.containers.Network;
+import org.testcontainers.containers.output.Slf4jLogConsumer;
import java.util.Collection;
import java.util.Collections;
@@ -53,7 +54,8 @@ public final class ShardingSphereContainers implements AutoCloseable {
public <T extends ShardingSphereContainer> T registerContainer(final T container, final String hostname) {
container.setNetwork(network);
container.setNetworkAliases(Collections.singletonList(hostname));
- container.withLogConsumer(ContainerLogs.newConsumer(String.join("-", testSuiteName, container.getName())));
+ String loggerName = String.join(":", testSuiteName, container.getName());
+ container.withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(loggerName), true));
containers.add(container);
return container;
}
diff --git a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/logging/ContainerLogs.java b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/logging/ContainerLogs.java
deleted file mode 100644
index cd36f2f..0000000
--- a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/framework/container/logging/ContainerLogs.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.
- */
-
-package org.apache.shardingsphere.test.integration.framework.container.logging;
-
-import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.Logger;
-import ch.qos.logback.classic.LoggerContext;
-import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.ConsoleAppender;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.slf4j.LoggerFactory;
-import org.testcontainers.containers.output.BaseConsumer;
-import org.testcontainers.containers.output.Slf4jLogConsumer;
-
-/**
- * Container logs.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ContainerLogs {
-
- /**
- * Create new log consumer.
- *
- * @param serviceName service name
- * @return log consumer
- */
- public static BaseConsumer<?> newConsumer(final String serviceName) {
- LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
- Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(serviceName);
- logger.addAppender(createLogAppender(context));
- logger.setLevel(Level.DEBUG);
- logger.setAdditive(false);
- Slf4jLogConsumer result = new Slf4jLogConsumer(logger, true);
- result.withPrefix(serviceName);
- return result;
- }
-
- private static ConsoleAppender<ILoggingEvent> createLogAppender(final LoggerContext context) {
- ConsoleAppender<ILoggingEvent> result = new ConsoleAppender<>();
- result.setEncoder(createPatternLayoutEncoder(context));
- result.start();
- return result;
- }
-
- private static PatternLayoutEncoder createPatternLayoutEncoder(final LoggerContext context) {
- PatternLayoutEncoder result = new PatternLayoutEncoder();
- result.setContext(context);
- result.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %msg%n");
- result.start();
- return result;
- }
-}