aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
authorMarius Volkhart <mariusvolkhart@apache.org>2021-02-21 20:57:25 +0000
committerMarius Volkhart <mariusvolkhart@apache.org>2021-02-21 20:57:25 +0000
commit259c9967efb354a0feff2a861ac8bd20582b6562 (patch)
treeba76a4f20503d97e77bdf18146d59e00a2369fb9 /src/testcases/org/apache
parent6d10f26718f84591671d7cafdcc009345b9c777e (diff)
downloadpoi-259c9967efb354a0feff2a861ac8bd20582b6562.tar.gz
poi-259c9967efb354a0feff2a861ac8bd20582b6562.zip
[bug-63046] Use Log4j 2 for logging
This removes the POILogger and POILogFactory mechanism for logging. This mechanism was created at a time when the Java landscape looked very different than it does today. Log4j 2 is an Apache Foundation project that is well maintained and is widely regarded as having good performance and capabilities. We use only the Log4j API artifact. This lets application developers choose how they want to capture logging events if at all. Integrations with Log4j 2 Core and Logback are available from the Log4j project. Closes #224 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1886770 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/hpsf/basic/TestWrite.java17
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java2
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java14
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java16
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java25
-rw-r--r--src/testcases/org/apache/poi/util/DummyPOILogger.java51
-rw-r--r--src/testcases/org/apache/poi/util/TestPOILogger.java83
7 files changed, 23 insertions, 185 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
index b5294bcc48..85ae090206 100644
--- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
+++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java
@@ -94,27 +94,10 @@ class TestWrite {
"\"de_DE\".";
/*
- private static String loggerBefore;
-
@BeforeClass
public static void setUpClass() {
- loggerBefore = System.getProperty("org.apache.poi.util.POILogger");
-
- // this test may fails in newer JDKs because of disallowed access if
- // properties are missing, make this visible
- System.setProperty("org.apache.poi.util.POILogger", CommonsLogger.class.getName());
-
VariantSupport.setLogUnsupportedTypes(false);
}
-
- @AfterClass
- public static void tearDownClass() {
- if(loggerBefore == null) {
- System.clearProperty("org.apache.poi.util.POILogger");
- } else {
- System.setProperty("org.apache.poi.util.POILogger", loggerBefore);
- }
- }
*/
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
index 6e1698cadd..98195b11d5 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
@@ -31,8 +31,6 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.junit.jupiter.api.Test;
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
index 6d5a9da58a..d56c3d6134 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestMatrixFormulasFromBinarySpreadsheet.java
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.usermodel;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -27,6 +28,8 @@ import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.functions.TestMathX;
@@ -37,8 +40,6 @@ import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.util.LocaleUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
@@ -46,7 +47,7 @@ import org.junit.jupiter.params.provider.MethodSource;
final class TestMatrixFormulasFromBinarySpreadsheet {
- private static final POILogger LOG = POILogFactory.getLogger(TestMatrixFormulasFromBinarySpreadsheet.class);
+ private static final Logger LOG = LogManager.getLogger(TestMatrixFormulasFromBinarySpreadsheet.class);
private static HSSFWorkbook workbook;
@@ -204,14 +205,13 @@ final class TestMatrixFormulasFromBinarySpreadsheet {
*/
private static String getTargetFunctionName(Row r) {
if(r == null) {
- LOG.log(POILogger.WARN,"Warning - given null row, can't figure out function name");
+ LOG.atWarn().log("Warning - given null row, can't figure out function name");
return null;
}
Cell cell = r.getCell(Navigator.START_OPERATORS_COL_INDEX);
- LOG.log(POILogger.INFO, String.valueOf(Navigator.START_OPERATORS_COL_INDEX));
+ LOG.atInfo().log("{}", box(Navigator.START_OPERATORS_COL_INDEX));
if(cell == null) {
- LOG.log(POILogger.WARN,
- "Warning - Row " + r.getRowNum() + " has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name");
+ LOG.atWarn().log("Row {} has no cell " + Navigator.START_OPERATORS_COL_INDEX + ", can't figure out function name", box(r.getRowNum()));
return null;
}
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
index 73c0423859..c594fb513d 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
@@ -24,26 +24,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Consumer;
import java.util.stream.Stream;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.util.IOUtils;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
final class TestEmptyDocument {
- private static final POILogger LOG = POILogFactory.getLogger(TestEmptyDocument.class);
+ private static final Logger LOG = LogManager.getLogger(TestEmptyDocument.class);
- private interface EmptyDoc {
+ private interface EmptyDoc {
void handle(DirectoryEntry dir) throws IOException;
}
@@ -61,7 +55,7 @@ final class TestEmptyDocument {
}
private static void SingleEmptyDocumentEvent(DirectoryEntry dir) throws IOException {
- dir.createDocument("Foo", 0, event -> LOG.log(POILogger.WARN, "written"));
+ dir.createDocument("Foo", 0, event -> LOG.atWarn().log("written"));
}
private static void EmptyDocumentWithFriend(DirectoryEntry dir) throws IOException {
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
index a82a2a8681..bcd8bf272a 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestBugzillaIssues.java
@@ -17,6 +17,7 @@
package org.apache.poi.ss.usermodel;
+import static org.apache.logging.log4j.util.Unbox.box;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -38,6 +39,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.ss.ITestDataProvider;
@@ -48,8 +51,6 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellRangeAddressList;
import org.apache.poi.ss.util.PaneInformation;
import org.apache.poi.ss.util.SheetUtil;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
@@ -57,7 +58,7 @@ import org.junit.jupiter.api.Test;
* A base class for bugzilla issues that can be described in terms of common ss interfaces.
*/
public abstract class BaseTestBugzillaIssues {
- private static final POILogger LOG = POILogFactory.getLogger(BaseTestBugzillaIssues.class);
+ private static final Logger LOG = LogManager.getLogger(BaseTestBugzillaIssues.class);
private static final String TEST_32 = "Some text with 32 characters to ";
private static final String TEST_255 = "Some very long text that is exactly 255 characters, which are allowed here, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla bla, bla.....";
@@ -1388,7 +1389,7 @@ public abstract class BaseTestBugzillaIssues {
// Create a workbook
try (Workbook wb = _testDataProvider.createWorkbook(nrows+1)) {
final Sheet sh = wb.createSheet();
- LOG.log(POILogger.DEBUG, wb.getClass().getName(), " column autosizing timing...");
+ LOG.atDebug().log("{} column autosizing timing...", wb.getClass().getName());
final long t0 = time();
_testDataProvider.trackAllColumnsForAutosizing(sh);
@@ -1401,28 +1402,24 @@ public abstract class BaseTestBugzillaIssues {
}
final double populateSheetTime = delta(t0);
final double populateSheetTimePerCell_ns = (1000000 * populateSheetTime / (nrows * ncols));
- if (LOG.check(POILogger.DEBUG)) {
- LOG.log(POILogger.DEBUG, "Populate sheet time: ", populateSheetTime, " ms (", populateSheetTimePerCell_ns, " ns/cell)");
+ LOG.atDebug().log("Populate sheet time: {} ms ({} ns/cell)", populateSheetTime, populateSheetTimePerCell_ns);
- LOG.log(POILogger.DEBUG, "Autosizing...");
- }
+ LOG.atDebug().log("Autosizing...");
final long t1 = time();
for (int c = 0; c < ncols; c++) {
final long t2 = time();
sh.autoSizeColumn(c);
- LOG.log(POILogger.DEBUG, "Column ", c, " took ", delta(t2), " ms");
+ LOG.atDebug().log("Column {} took {} ms", box(c),delta(t2));
}
final double autoSizeColumnsTime = delta(t1);
final double autoSizeColumnsTimePerColumn = autoSizeColumnsTime / ncols;
final double bestFitWidthTimePerCell_ns = 1000000 * autoSizeColumnsTime / (ncols * nrows);
- if (LOG.check(POILogger.DEBUG)) {
- LOG.log(POILogger.DEBUG, "Auto sizing columns took a total of ", autoSizeColumnsTime, " ms (", autoSizeColumnsTimePerColumn, " ms per column)");
- LOG.log(POILogger.DEBUG, "Best fit width time per cell: ", bestFitWidthTimePerCell_ns, " ns");
- }
+ LOG.atDebug().log("Auto sizing columns took a total of {} ms ({} ms per column)", autoSizeColumnsTime, autoSizeColumnsTimePerColumn);
+ LOG.atDebug().log("Best fit width time per cell: {} ns", bestFitWidthTimePerCell_ns);
final double totalTime_s = (populateSheetTime + autoSizeColumnsTime) / 1000;
- LOG.log(POILogger.DEBUG, "Total time: ", totalTime_s, " s");
+ LOG.atDebug().log("Total time: {} s", totalTime_s);
}
//if (bestFitWidthTimePerCell_ns > 50000) {
diff --git a/src/testcases/org/apache/poi/util/DummyPOILogger.java b/src/testcases/org/apache/poi/util/DummyPOILogger.java
deleted file mode 100644
index bb6526be2d..0000000000
--- a/src/testcases/org/apache/poi/util/DummyPOILogger.java
+++ /dev/null
@@ -1,51 +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.poi.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * {@link POILogger} which logs into an ArrayList so that
- * tests can see what got logged
- */
-@Internal
-public class DummyPOILogger implements POILogger {
- public List<String>logged = new ArrayList<>();
-
- public void reset() {
- logged = new ArrayList<>();
- }
-
- @Override
- public boolean check(int level) {
- return true;
- }
-
- @Override
- public void initialize(String cat) {}
-
- @Override
- public void _log(int level, Object obj1) {
- logged.add(level + " - " + obj1);
- }
-
- @Override
- public void _log(int level, Object obj1, Throwable exception) {
- logged.add(level + " - " + obj1 + " - " + exception);
- }
-}
diff --git a/src/testcases/org/apache/poi/util/TestPOILogger.java b/src/testcases/org/apache/poi/util/TestPOILogger.java
deleted file mode 100644
index 4829ca2d36..0000000000
--- a/src/testcases/org/apache/poi/util/TestPOILogger.java
+++ /dev/null
@@ -1,83 +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.poi.util;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests the log class.
- */
-public final class TestPOILogger implements POILogger {
- private String lastLog = "";
- private Throwable lastEx;
-
- /**
- * Test different types of log output.
- */
- @Test
- void testVariousLogTypes() throws Exception {
- String oldLCN = POILogFactory._loggerClassName;
- try {
- POILogFactory._loggerClassName = TestPOILogger.class.getName();
- POILogger log = POILogFactory.getLogger( "foo" );
- assertTrue(log instanceof TestPOILogger);
-
- TestPOILogger tLog = (TestPOILogger)log;
-
- log.log(POILogger.WARN, "Test = ", 1);
- assertEquals("Test = 1", tLog.lastLog);
-
- log.log(POILogger.ERROR, "Test ", 1,2,new Exception("bla"));
- assertEquals("Test 12", tLog.lastLog);
- assertNotNull(tLog.lastEx);
-
- log.log(POILogger.ERROR, "log\nforging", "\nevil","\nlog");
- assertEquals("log forging evil log", tLog.lastLog);
- } finally {
- POILogFactory._loggerClassName = oldLCN;
- }
- }
-
- // ---------- POI Logger methods implemented for testing ----------
-
- @Override
- public void initialize(String cat) {
- }
-
- @Override
- public void _log(int level, Object obj1) {
- lastLog = (obj1 == null) ? "" : obj1.toString();
- lastEx = null;
- }
-
- @Override
- public void _log(int level, Object obj1, Throwable exception) {
- lastLog = (obj1 == null) ? "" : obj1.toString();
- lastEx = exception;
- }
-
- @Override
- public boolean check(int level) {
- return true;
- }
-}