You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2018/03/31 07:17:19 UTC

[incubator-servicecomb-java-chassis] 01/07: SCB-384 make collect log in UT easier

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

wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git

commit 1bc43133fa523362f8a6db697296e83822ee4a47
Author: wujimin <wu...@huawei.com>
AuthorDate: Fri Mar 23 16:33:36 2018 +0800

    SCB-384 make collect log in UT easier
---
 foundations/foundation-test-scaffolding/pom.xml    |  4 ++
 .../test/scaffolding/log/LogCollector.java         | 58 ++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/foundations/foundation-test-scaffolding/pom.xml b/foundations/foundation-test-scaffolding/pom.xml
index abfe024..06b05b9 100644
--- a/foundations/foundation-test-scaffolding/pom.xml
+++ b/foundations/foundation-test-scaffolding/pom.xml
@@ -48,5 +48,9 @@
       <groupId>com.netflix.spectator</groupId>
       <artifactId>spectator-reg-servo</artifactId>
     </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
   </dependencies>
 </project>
diff --git a/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/log/LogCollector.java b/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/log/LogCollector.java
new file mode 100644
index 0000000..33e5808
--- /dev/null
+++ b/foundations/foundation-test-scaffolding/src/main/java/org/apache/servicecomb/foundation/test/scaffolding/log/LogCollector.java
@@ -0,0 +1,58 @@
+/*
+ * 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.servicecomb.foundation.test.scaffolding.log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Appender;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggingEvent;
+
+public class LogCollector {
+  List<LoggingEvent> events = new ArrayList<>();
+
+  Appender appender = new AppenderSkeleton() {
+    @Override
+    public void append(LoggingEvent event) {
+      events.add(event);
+    }
+
+    @Override
+    public void close() {
+
+    }
+
+    @Override
+    public boolean requiresLayout() {
+      return false;
+    }
+  };
+
+  public LogCollector() {
+    Logger.getRootLogger().addAppender(appender);
+  }
+
+  public List<LoggingEvent> getEvents() {
+    return events;
+  }
+
+  public void teardown() {
+    Logger.getRootLogger().removeAppender(appender);
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
wujimin@apache.org.