From bc921a1bbdd0a4058b48c8da3079e9984a6ce66f Mon Sep 17 00:00:00 2001 From: abhishek Date: Wed, 18 May 2022 20:02:34 +0530 Subject: [PATCH] ZCS-11112 : Upgrading log4j libraries for test classes --- .../com/zimbra/common/soap/ElementTest.java | 15 ++++++----- .../src/java/com/zimbra/common/util/Log.java | 2 +- .../com/zimbra/doc/soap/ChangelogTest.java | 15 ++++++----- .../doc/soap/XmlElementDescription.java | 16 ++++++------ .../com/zimbra/soap/JaxbToJsonTest.java | 15 ++++++----- .../zimbra/soap/admin/DumpSessionsTest.java | 15 ++++++----- .../zimbra/soap/admin/GetAllConfigTest.java | 15 ++++++----- .../soap/admin/MailQueueActionTest.java | 15 ++++++----- .../zimbra/soap/mail/SendMsgRequestTest.java | 15 ++++++----- soap/src/java-test/log4j-test.properties | 20 +++++++++++--- store/src/java-test/log4j-test.properties | 26 +++++++++++++------ 11 files changed, 99 insertions(+), 70 deletions(-) diff --git a/common/src/java-test/com/zimbra/common/soap/ElementTest.java b/common/src/java-test/com/zimbra/common/soap/ElementTest.java index ae862af4505..7ea9b24aca4 100644 --- a/common/src/java-test/com/zimbra/common/soap/ElementTest.java +++ b/common/src/java-test/com/zimbra/common/soap/ElementTest.java @@ -27,9 +27,10 @@ import java.nio.charset.StandardCharsets; import java.util.List; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.dom4j.DocumentException; import org.dom4j.QName; import org.dom4j.io.SAXReader; @@ -54,7 +55,7 @@ public class ElementTest { @Rule public TestName testName = new TestName(); - private static final Logger LOG = Logger.getLogger(ElementTest.class); + private static final Logger LOG = LogManager.getLogger(ElementTest.class); private static final int maxiter = 50000; private static final ByteArrayInputStream getInfoRespBais = toBais(ElementTest.class.getResourceAsStream("GetInfoResponseSOAP.xml")); @@ -62,9 +63,9 @@ public class ElementTest { toBais(ElementTest.class.getResourceAsStream("GetInfoRequestSOAP.xml")); static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } private void logInfo(String format, Object ... objects) { diff --git a/common/src/java/com/zimbra/common/util/Log.java b/common/src/java/com/zimbra/common/util/Log.java index e184369a669..905bd78dde7 100644 --- a/common/src/java/com/zimbra/common/util/Log.java +++ b/common/src/java/com/zimbra/common/util/Log.java @@ -443,7 +443,7 @@ public void errorQuietly(String format, Object o, Throwable t) { } /** - * Returns Log4j equivalent of {@code level} or org.apache.log4j.Level.TRACE + * Returns Log4j equivalent of {@code level} or org.apache.logging.log4j.Level.TRACE */ private static final org.apache.logging.log4j.Level log4jLevel(Level level) { org.apache.logging.log4j.Level log4jlevel = ZIMBRA_TO_LOG4J.get(level); diff --git a/soap/soapdocs/src/java-test/com/zimbra/doc/soap/ChangelogTest.java b/soap/soapdocs/src/java-test/com/zimbra/doc/soap/ChangelogTest.java index 0d1de3a6508..52db17b1629 100644 --- a/soap/soapdocs/src/java-test/com/zimbra/doc/soap/ChangelogTest.java +++ b/soap/soapdocs/src/java-test/com/zimbra/doc/soap/ChangelogTest.java @@ -21,9 +21,10 @@ import java.util.List; import java.util.Map; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.junit.Assert; import org.junit.BeforeClass; @@ -48,12 +49,12 @@ public class ChangelogTest { - private static final Logger LOG = Logger.getLogger(ChangelogTest.class); + private static final Logger LOG = LogManager.getLogger(ChangelogTest.class); static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } @BeforeClass diff --git a/soap/soapdocs/src/java/com/zimbra/doc/soap/XmlElementDescription.java b/soap/soapdocs/src/java/com/zimbra/doc/soap/XmlElementDescription.java index b2d8ec4827a..5a0b3aeae8a 100644 --- a/soap/soapdocs/src/java/com/zimbra/doc/soap/XmlElementDescription.java +++ b/soap/soapdocs/src/java/com/zimbra/doc/soap/XmlElementDescription.java @@ -31,10 +31,10 @@ import com.zimbra.soap.util.JaxbValueInfo; import com.zimbra.soap.util.WrappedElementInfo; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; - +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; /** * Represents a description of an XML element and all the attributes and elements it contains */ @@ -67,11 +67,11 @@ public class XmlElementDescription // this will point at that (otherwise, remains null) private XmlElementDescription masterDescriptionForThisJaxbClass = null; - private static final Logger LOG = Logger.getLogger(DescriptionNode.class); + private static final Logger LOG = LogManager.getLogger(DescriptionNode.class); static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } private XmlElementDescription(boolean isSingleton, boolean isWrapper, boolean isOptional) { diff --git a/soap/src/java-test/com/zimbra/soap/JaxbToJsonTest.java b/soap/src/java-test/com/zimbra/soap/JaxbToJsonTest.java index 9eb471e5696..3e127b5fbf7 100644 --- a/soap/src/java-test/com/zimbra/soap/JaxbToJsonTest.java +++ b/soap/src/java-test/com/zimbra/soap/JaxbToJsonTest.java @@ -36,9 +36,10 @@ import javax.xml.bind.annotation.XmlMixed; import javax.xml.parsers.DocumentBuilder; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.dom4j.QName; import org.junit.Ignore; import org.junit.Rule; @@ -118,7 +119,7 @@ public class JaxbToJsonTest { @Rule public TestName testName = new TestName(); - private static final Logger LOG = Logger.getLogger(JaxbToJsonTest.class); + private static final Logger LOG = LogManager.getLogger(JaxbToJsonTest.class); private static String jsonEmptyGetSystemRetentionPolicyResponse = "{\n" + @@ -149,9 +150,9 @@ public class JaxbToJsonTest { "}"; static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } private void logDebug(String format, Object ... objects) { diff --git a/soap/src/java-test/com/zimbra/soap/admin/DumpSessionsTest.java b/soap/src/java-test/com/zimbra/soap/admin/DumpSessionsTest.java index 9f7085252e3..a0b6211a0ba 100644 --- a/soap/src/java-test/com/zimbra/soap/admin/DumpSessionsTest.java +++ b/soap/src/java-test/com/zimbra/soap/admin/DumpSessionsTest.java @@ -26,9 +26,10 @@ import javax.xml.bind.Unmarshaller; import javax.xml.namespace.QName; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.junit.Assert; import org.junit.BeforeClass; @@ -48,15 +49,15 @@ */ public class DumpSessionsTest { - private static final Logger LOG = Logger.getLogger(DumpSessionsTest.class); + private static final Logger LOG = LogManager.getLogger(DumpSessionsTest.class); private static Unmarshaller unmarshaller; private static Marshaller marshaller; static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } @BeforeClass diff --git a/soap/src/java-test/com/zimbra/soap/admin/GetAllConfigTest.java b/soap/src/java-test/com/zimbra/soap/admin/GetAllConfigTest.java index 02af3bbb93f..307a8620f41 100644 --- a/soap/src/java-test/com/zimbra/soap/admin/GetAllConfigTest.java +++ b/soap/src/java-test/com/zimbra/soap/admin/GetAllConfigTest.java @@ -21,9 +21,10 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.junit.Assert; import org.junit.BeforeClass; @@ -43,14 +44,14 @@ */ public class GetAllConfigTest { - private static final Logger LOG = Logger.getLogger(GetAllConfigTest.class); + private static final Logger LOG = LogManager.getLogger(GetAllConfigTest.class); private static Unmarshaller unmarshaller; static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } @BeforeClass diff --git a/soap/src/java-test/com/zimbra/soap/admin/MailQueueActionTest.java b/soap/src/java-test/com/zimbra/soap/admin/MailQueueActionTest.java index 3f19273021d..1fb2056ddc8 100644 --- a/soap/src/java-test/com/zimbra/soap/admin/MailQueueActionTest.java +++ b/soap/src/java-test/com/zimbra/soap/admin/MailQueueActionTest.java @@ -23,9 +23,10 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.junit.Assert; import org.junit.BeforeClass; @@ -46,15 +47,15 @@ */ public class MailQueueActionTest { - private static final Logger LOG = Logger.getLogger(MailQueueActionTest.class); + private static final Logger LOG = LogManager.getLogger(MailQueueActionTest.class); private static Unmarshaller unmarshaller; private static Marshaller marshaller; static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } @BeforeClass diff --git a/soap/src/java-test/com/zimbra/soap/mail/SendMsgRequestTest.java b/soap/src/java-test/com/zimbra/soap/mail/SendMsgRequestTest.java index 9ccacf52100..9b61036ea24 100644 --- a/soap/src/java-test/com/zimbra/soap/mail/SendMsgRequestTest.java +++ b/soap/src/java-test/com/zimbra/soap/mail/SendMsgRequestTest.java @@ -18,9 +18,10 @@ import java.util.List; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; -import org.apache.log4j.Level; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Level; import org.junit.Assert; import org.junit.BeforeClass; @@ -44,12 +45,12 @@ public final class SendMsgRequestTest { @Rule public TestName testName = new TestName(); - private static final Logger LOG = Logger.getLogger(SendMsgRequestTest.class); + private static final Logger LOG = LogManager.getLogger(SendMsgRequestTest.class); static { - BasicConfigurator.configure(); - Logger.getRootLogger().setLevel(Level.INFO); - LOG.setLevel(Level.INFO); + Configurator.reconfigure(); + Configurator.setRootLevel(Level.INFO); + Configurator.setLevel(LOG.getName(), Level.INFO); } private void logInfo(String format, Object ... objects) { diff --git a/soap/src/java-test/log4j-test.properties b/soap/src/java-test/log4j-test.properties index cb8653b086c..ceb6c38d759 100644 --- a/soap/src/java-test/log4j-test.properties +++ b/soap/src/java-test/log4j-test.properties @@ -12,8 +12,20 @@ # You should have received a copy of the GNU General Public License along with this program. # If not, see . # ***** END LICENSE BLOCK ***** +status = error +dest = err +name = PropertiesConfig +packages = com.zimbra -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout = org.apache.log4j.SimpleLayout -log4j.logger.zimbra.test=INFO -log4j.rootLogger = INFO,stdout +appender.test.type = ConsoleAppender +appender.test.name = TestAppender +appender.test.layout.type = PatternLayout +appender.test.layout.pattern = %d %-5p [%t] [%z] %c{1} - %m%n + +logger.test.name = testConsole +logger.test.level = info +logger.test.additivity = false +logger.test.appenderRef.stdout.ref = TestAppender + +rootLogger.level = INFO +rootLogger.appenderRef.stdout.ref = TestAppender diff --git a/store/src/java-test/log4j-test.properties b/store/src/java-test/log4j-test.properties index 53607841e57..f4e18f60dcf 100644 --- a/store/src/java-test/log4j-test.properties +++ b/store/src/java-test/log4j-test.properties @@ -1,6 +1,6 @@ # ***** BEGIN LICENSE BLOCK ***** # Zimbra Collaboration Suite Server -# Copyright (C) 2011, 2012, 2013, 2014, 2016 Synacor, Inc. +# Copyright (C) 2022 Synacor, Inc. # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software Foundation, @@ -13,10 +13,20 @@ # If not, see . # ***** END LICENSE BLOCK ***** -log4j.appender.stdout = org.apache.log4j.ConsoleAppender -log4j.appender.stdout.layout = org.apache.log4j.SimpleLayout -log4j.org.apache.cassandra = INFO -log4j.logger.zimbra.test=DEBUG -#log4j.logger.zimbra.sqltrace=TRACE -log4j.rootLogger = INFO,stdout -log4j.logger.zimbra.elasticsearch=INFO +status = error +dest = err +name = PropertiesConfig +packages = com.zimbra + +appender.teststore.type = ConsoleAppender +appender.teststore.name = TestStoreAppender +appender.teststore.layout.type = PatternLayout +appender.teststore.layout.pattern = %d %-5p [%t] [%z] %c{1} - %m%n + +logger.A1.name = org.apache.cassandra +logger.A1.level = info +logger.A1.additivity = false +logger.A1.appenderRef.file.ref = TestStoreAppender + +rootLogger.level = INFO +rootLogger.appenderRef.stdout.ref = TestAppender