Skip to content

Commit

Permalink
ZCS-11112 : Upgrading log4j libraries for test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdeshmukh2209 committed May 18, 2022
1 parent 817d91e commit bc921a1
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 70 deletions.
15 changes: 8 additions & 7 deletions common/src/java-test/com/zimbra/common/soap/ElementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,17 +55,17 @@ 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"));
private static final ByteArrayInputStream getInfoReqBais =
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) {
Expand Down
2 changes: 1 addition & 1 deletion common/src/java/com/zimbra/common/util/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions soap/src/java-test/com/zimbra/soap/JaxbToJsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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" +
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 8 additions & 7 deletions soap/src/java-test/com/zimbra/soap/admin/DumpSessionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions soap/src/java-test/com/zimbra/soap/admin/GetAllConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions soap/src/java-test/com/zimbra/soap/mail/SendMsgRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
20 changes: 16 additions & 4 deletions soap/src/java-test/log4j-test.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@
# You should have received a copy of the GNU General Public License along with this program.
# If not, see <http://www.gnu.org/licenses/>.
# ***** 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
26 changes: 18 additions & 8 deletions store/src/java-test/log4j-test.properties
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,10 +13,20 @@
# If not, see <https://www.gnu.org/licenses/>.
# ***** 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

0 comments on commit bc921a1

Please sign in to comment.