diff --git a/component/pom.xml b/component/pom.xml index 3af5419..a27afe9 100644 --- a/component/pom.xml +++ b/component/pom.xml @@ -44,8 +44,8 @@ under the License. siddhi-query-api - org.apache.log4j.wso2 - log4j + org.apache.logging.log4j + log4j-core org.testng diff --git a/component/src/main/java/io/siddhi/extension/io/googlepubsub/sink/GooglePubSubSink.java b/component/src/main/java/io/siddhi/extension/io/googlepubsub/sink/GooglePubSubSink.java index deaeae7..fcb2ebe 100644 --- a/component/src/main/java/io/siddhi/extension/io/googlepubsub/sink/GooglePubSubSink.java +++ b/component/src/main/java/io/siddhi/extension/io/googlepubsub/sink/GooglePubSubSink.java @@ -46,7 +46,8 @@ import io.siddhi.core.util.transport.OptionHolder; import io.siddhi.extension.io.googlepubsub.util.GooglePubSubConstants; import io.siddhi.query.api.definition.StreamDefinition; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.FileInputStream; @@ -102,7 +103,7 @@ */ public class GooglePubSubSink extends Sink { - private static final Logger log = Logger.getLogger(GooglePubSubSink.class); + private static final Logger log = LogManager.getLogger(GooglePubSubSink.class); private String streamID; private String siddhiAppName; private GoogleCredentials credentials; diff --git a/component/src/main/java/io/siddhi/extension/io/googlepubsub/source/GooglePubSubSource.java b/component/src/main/java/io/siddhi/extension/io/googlepubsub/source/GooglePubSubSource.java index d603b2b..bf8d2c4 100644 --- a/component/src/main/java/io/siddhi/extension/io/googlepubsub/source/GooglePubSubSource.java +++ b/component/src/main/java/io/siddhi/extension/io/googlepubsub/source/GooglePubSubSource.java @@ -44,7 +44,8 @@ import io.siddhi.core.util.snapshot.state.StateFactory; import io.siddhi.core.util.transport.OptionHolder; import io.siddhi.extension.io.googlepubsub.util.GooglePubSubConstants; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.FileInputStream; @@ -106,7 +107,7 @@ public class GooglePubSubSource extends Source { - private static final Logger log = Logger.getLogger(GooglePubSubSource.class); + private static final Logger log = LogManager.getLogger(GooglePubSubSource.class); private String streamID; private String siddhiAppName; private SubscriptionAdminClient subscriptionAdminClient; diff --git a/component/src/main/resources/log4j.properties b/component/src/main/resources/log4j.properties deleted file mode 100644 index 456fa86..0000000 --- a/component/src/main/resources/log4j.properties +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -# -# WSO2 Inc. 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. -# -# For the general syntax of property based configuration files see the -# documenation of org.apache.log4j.PropertyConfigurator. - -# The root category uses the appender called A1. Since no priority is -# specified, the root category assumes the default priority for root -# which is DEBUG in log4j. The root category is the only category that -# has a default priority. All other categories need not be assigned a -# priority in which case they inherit their priority from the -# hierarchy. - -#log4j.rootLogger=DEBUG, stdout -log4j.rootLogger=INFO, stdout - -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%m%n -#log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %x - %m%n diff --git a/component/src/main/resources/log4j2.properties b/component/src/main/resources/log4j2.properties new file mode 100755 index 0000000..2ce5010 --- /dev/null +++ b/component/src/main/resources/log4j2.properties @@ -0,0 +1,40 @@ +# +# /* +# * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# * +# * WSO2 Inc. 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. +# */ +# + + +# For the general syntax of property based configuration files see the +# documenation of org.apache.log4j.PropertyConfigurator. + +# The root category uses the appender called A1. Since no priority is +# specified, the root category assumes the default priority for root +# which is DEBUG in log4j. The root category is the only category that +# has a default priority. All other categories need not be assigned a +# priority in which case they inherit their priority from the +# hierarchy. + +# Console appender configuration +appender.console.type = Console +appender.console.name = consoleLogger +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%t] %-5p %c %x - %m%n + +# Root logger referring to console appender +rootLogger.level = info +rootLogger.appenderRef.stdout.ref = consoleLogger diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink1.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink1.java index a680456..0d881e8 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink1.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink1.java @@ -24,7 +24,9 @@ import io.siddhi.core.stream.input.InputHandler; import io.siddhi.core.stream.output.StreamCallback; import io.siddhi.extension.io.googlepubsub.util.ResultContainer; -import org.apache.log4j.Logger; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -33,7 +35,7 @@ public class TestCaseOfGooglePubSubSink1 { - private static Logger log = Logger.getLogger(TestCaseOfGooglePubSubSink1.class); + private static final Logger log = LogManager.getLogger(TestCaseOfGooglePubSubSink1.class); private volatile int count; private volatile boolean eventArrived; diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink2.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink2.java index bf69e5a..1d8c8d0 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink2.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestCaseOfGooglePubSubSink2.java @@ -22,17 +22,18 @@ import io.siddhi.core.SiddhiManager; import io.siddhi.core.exception.SiddhiAppCreationException; import io.siddhi.core.stream.input.InputHandler; -import io.siddhi.core.stream.output.sink.Sink; import io.siddhi.extension.io.googlepubsub.util.UnitTestAppender; import io.siddhi.query.api.exception.SiddhiAppValidationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; public class TestCaseOfGooglePubSubSink2 { - private static Logger log = Logger.getLogger(TestCaseOfGooglePubSubSink1.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfGooglePubSubSink1.class); private volatile int count; private volatile boolean eventArrived; @@ -102,9 +103,11 @@ public void googlePubSubSimplePublishTest3() throws InterruptedException { log.info("-----------------------------------------------------------------"); log.info("Test to publish messages to a non-existing project in the server."); log.info("-----------------------------------------------------------------"); - log = Logger.getLogger(Sink.class); - UnitTestAppender testAppender = new UnitTestAppender(); - log.addAppender(testAppender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); // deploying the execution plan SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( @@ -120,10 +123,11 @@ public void googlePubSubSimplePublishTest3() throws InterruptedException { siddhiAppRuntime.start(); fooStream.send(new Object[]{"World"}); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(testAppender - .getMessages() - .contains("An error is caused due to a resource NOT_FOUND in Google Pub Sub server")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages(). + contains("An error is caused due to a resource NOT_FOUND in Google Pub Sub server")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } /** @@ -135,9 +139,11 @@ public void googlePubSubSimplePublishTest4() throws InterruptedException { log.info("-----------------------------------------------------------"); log.info("Test to publish messages by specifying project.id as empty."); log.info("-----------------------------------------------------------"); - log = Logger.getLogger(Sink.class); - UnitTestAppender testAppender = new UnitTestAppender(); - log.addAppender(testAppender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); // deploying the execution plan SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( @@ -153,9 +159,10 @@ public void googlePubSubSimplePublishTest4() throws InterruptedException { siddhiAppRuntime.start(); fooStream.send(new Object[]{"World"}); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(testAppender - .getMessages() - .contains("An error is caused due to a resource NOT_FOUND in Google Pub Sub server")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages(). + contains("An error is caused due to a resource NOT_FOUND in Google Pub Sub server")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } } diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestSubscriber.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestSubscriber.java index 42d5c56..5f9a11d 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestSubscriber.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/sink/TestSubscriber.java @@ -31,7 +31,8 @@ import com.google.pubsub.v1.PubsubMessage; import com.google.pubsub.v1.PushConfig; import io.siddhi.extension.io.googlepubsub.util.ResultContainer; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.FileInputStream; @@ -43,7 +44,7 @@ */ public class TestSubscriber { - private static final Logger log = Logger.getLogger(TestSubscriber.class); + private static final Logger log = LogManager.getLogger(TestSubscriber.class); private ResultContainer resultContainer; private boolean eventArrived; private int count; diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource1.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource1.java index e973fc9..3efd895 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource1.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource1.java @@ -24,7 +24,8 @@ import io.siddhi.core.stream.input.source.Source; import io.siddhi.core.stream.output.StreamCallback; import io.siddhi.core.util.SiddhiTestHelper; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -34,7 +35,7 @@ public class TestCaseOfGooglePubSubSource1 { - private static Logger log = Logger.getLogger(TestCaseOfGooglePubSubSource1.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfGooglePubSubSource1.class); private AtomicInteger count = new AtomicInteger(0); private AtomicInteger count1 = new AtomicInteger(0); private int waitTime = 50; @@ -211,7 +212,6 @@ public void testGooglePubSubSourcePause() throws Exception { log.info("--------------------------------------------------------------------------------"); log.info("Test to configure Google Pub Sub Source with pausing and resuming functionality."); log.info("--------------------------------------------------------------------------------"); - log = Logger.getLogger(GooglePubSubSource.class); // deploying the execution plan SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource2.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource2.java index 3e3543f..89a7d0b 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource2.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestCaseOfGooglePubSubSource2.java @@ -23,7 +23,9 @@ import io.siddhi.core.exception.SiddhiAppCreationException; import io.siddhi.extension.io.googlepubsub.util.UnitTestAppender; import io.siddhi.query.api.exception.SiddhiAppValidationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Logger; import org.testng.AssertJUnit; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -32,7 +34,7 @@ public class TestCaseOfGooglePubSubSource2 { - private static Logger log = Logger.getLogger(TestCaseOfGooglePubSubSource1.class); + private static final Logger log = (Logger) LogManager.getLogger(TestCaseOfGooglePubSubSource1.class); private AtomicInteger count = new AtomicInteger(0); private AtomicInteger count1 = new AtomicInteger(0); private int waitTime = 50; @@ -83,9 +85,11 @@ public void testGooglePubSubSourceEvent4() { log.info("---------------------------------------------------------------------------------------------------"); log.info("Test to receive messages by subscribing to topic in an unavailable project of google pubsub server."); log.info("---------------------------------------------------------------------------------------------------"); - log = Logger.getLogger(GooglePubSubSource.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( "@App:name('TestExecutionPlan1') " @@ -100,8 +104,11 @@ public void testGooglePubSubSourceEvent4() { + "Define stream FooStream2 (message string);" + "from FooStream2 select message insert into BarStream2;"); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(appender.getMessages().contains("Error in connecting to the resources at ")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages(). + contains("Error in connecting to the resources at ")); siddhiAppRuntime.shutdown(); + logger.removeAppender(appender); } /** @@ -114,9 +121,11 @@ public void testGooglePubSubSourceEvent6() { log.info("----------------------------------------------------------------------------------------"); log.info("Test to receive messages by subscribing to a non-existing topic in google pubsub server."); log.info("----------------------------------------------------------------------------------------"); - log = Logger.getLogger(GooglePubSubSource.class); - UnitTestAppender appender = new UnitTestAppender(); - log.addAppender(appender); + UnitTestAppender appender = new UnitTestAppender("UnitTestAppender", null); + final Logger logger = (Logger) LogManager.getRootLogger(); + logger.setLevel(Level.ALL); + logger.addAppender(appender); + appender.start(); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( "@App:name('TestExecutionPlan1') " @@ -131,8 +140,11 @@ public void testGooglePubSubSourceEvent6() { + "Define stream FooStream2 (message string);" + "from FooStream2 select message insert into BarStream2;"); siddhiAppRuntime.start(); - AssertJUnit.assertTrue(appender.getMessages().contains("Error in connecting to the resources at ")); + AssertJUnit.assertTrue(((UnitTestAppender) logger.getAppenders(). + get("UnitTestAppender")).getMessages(). + contains("Error in connecting to the resources at ")); siddhiManager.shutdown(); + logger.removeAppender(appender); } /** diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestPublisher.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestPublisher.java index b1119ad..6b7fa91 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestPublisher.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/source/TestPublisher.java @@ -31,7 +31,8 @@ import com.google.pubsub.v1.PubsubMessage; import io.siddhi.core.exception.ConnectionUnavailableException; import io.siddhi.core.exception.SiddhiAppCreationException; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.io.File; import java.io.FileInputStream; @@ -44,7 +45,7 @@ */ public class TestPublisher { - private static final Logger log = Logger.getLogger(TestPublisher.class); + private static final Logger log = LogManager.getLogger(TestPublisher.class); private TopicAdminClient topicAdminClient; private String projectId; diff --git a/component/src/test/java/io/siddhi/extension/io/googlepubsub/util/UnitTestAppender.java b/component/src/test/java/io/siddhi/extension/io/googlepubsub/util/UnitTestAppender.java index 718fbb2..9a93bd5 100644 --- a/component/src/test/java/io/siddhi/extension/io/googlepubsub/util/UnitTestAppender.java +++ b/component/src/test/java/io/siddhi/extension/io/googlepubsub/util/UnitTestAppender.java @@ -18,35 +18,52 @@ */ package io.siddhi.extension.io.googlepubsub.util; -import org.apache.log4j.AppenderSkeleton; -import org.apache.log4j.spi.LoggingEvent; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.mvel2.util.StringAppender; /** * Util class to read the logs of test cases. */ -public class UnitTestAppender extends AppenderSkeleton { +@Plugin(name = "UnitTestAppender", + category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) +public class UnitTestAppender extends AbstractAppender { - private String messages; + private StringAppender messages = new StringAppender(); - @Override - protected void append(LoggingEvent loggingEvent) { + public UnitTestAppender(String name, Filter filter) { - messages = loggingEvent.getRenderedMessage(); + super(name, filter, null); } - @Override - public void close() { + @PluginFactory + public static UnitTestAppender createAppender( + @PluginAttribute("name") String name, + @PluginElement("Filter") Filter filter) { + return new UnitTestAppender(name, filter); } - @Override - public boolean requiresLayout() { + public String getMessages() { - return false; + String results = messages.toString(); + if (results.isEmpty()) { + return null; + } + return results; } - public String getMessages() { + @Override + public void append(LogEvent event) { - return messages; + messages.append(event.getMessage().getFormattedMessage()); } + } diff --git a/component/src/test/resources/log4j.properties b/component/src/test/resources/log4j.properties deleted file mode 100644 index 4075dd9..0000000 --- a/component/src/test/resources/log4j.properties +++ /dev/null @@ -1,14 +0,0 @@ -# For the general syntax of property based configuration files see the -# documenation of org.apache.log4j.PropertyConfigurator. -# The root category uses the appender called A1. Since no priority is -# specified, the root category assumes the default priority for root -# which is DEBUG in log4j. The root category is the only category that -# has a default priority. All other categories need not be assigned a -# priority in which case they inherit their priority from the -# hierarchy. -#log4j.rootLogger=DEBUG, stdout -log4j.rootLogger=INFO, stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%m%n -#log4j.appender.stdout.layout.ConversionPattern=[%t] %-5p %c %x - %m%n diff --git a/component/src/test/resources/log4j2.xml b/component/src/test/resources/log4j2.xml new file mode 100644 index 0000000..7ac45ed --- /dev/null +++ b/component/src/test/resources/log4j2.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index e416268..aa730d8 100644 --- a/pom.xml +++ b/pom.xml @@ -93,8 +93,8 @@ under the License. ${siddhi.version} - org.apache.log4j.wso2 - log4j + org.apache.logging.log4j + log4j-core ${log4j.version} @@ -195,9 +195,9 @@ under the License. - 5.1.5 + 5.1.21 [5.0.0,6.0.0) - 1.2.17.wso2v1 + 2.17.1 6.11 4.4.15 0.7.9 @@ -205,13 +205,13 @@ under the License. 1.9 23.6-jre 1.18.0 - 4.1.30.Final + 4.1.73.Final 2.0.17.Final UTF-8 1.8.0 - 5.0.2 - 5.0.2 - 2.0.1 + 5.2.2 + 5.2.2 + 2.1.1 0.7.9 3.0.0