From 00026a8d5bccae1568967ce41a83a744b5b57ea4 Mon Sep 17 00:00:00 2001 From: Haroon Khan Date: Sun, 26 Sep 2021 04:28:09 +0100 Subject: [PATCH] [JAVA-6005] Reduce logging (#11247) --- .../algorithms/prim/PrimUnitTest.java | 4 +- .../algorithms/suffixtree/SuffixTree.java | 10 +++-- .../algorithms/dfs/GraphUnitTest.java | 1 - .../quadtree/QuadTreeSearchUnitTest.java | 30 ++++++------- .../src/main/resources/log4j2.xml | 18 ++++++++ .../src/main/resources/log4j.properties | 42 +++++++++++++++++++ .../src/main/resources/logback.xml | 1 + core-java-modules/core-java-jar/pom.xml | 4 ++ jee-7/src/main/resources/logback.xml | 2 + .../src/main/resources/application.properties | 1 - .../BatchInsertIntegrationTest.java | 6 ++- .../application-batchinserts.properties | 4 +- .../resources/application-stats.properties | 5 +++ 13 files changed, 102 insertions(+), 26 deletions(-) create mode 100644 apache-libraries/src/main/resources/log4j2.xml create mode 100644 apache-spark/src/main/resources/log4j.properties create mode 100644 persistence-modules/spring-data-jpa-crud/src/test/resources/application-stats.properties diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java index 41e53fc9f2..fac3b3a81f 100644 --- a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/prim/PrimUnitTest.java @@ -1,10 +1,10 @@ package com.baeldung.algorithms.prim; +import org.junit.Test; + import java.util.ArrayList; import java.util.List; -import org.junit.Test; - public class PrimUnitTest { @Test diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree/SuffixTree.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree/SuffixTree.java index eb58c2bfab..b6b29ede78 100644 --- a/algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree/SuffixTree.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree/SuffixTree.java @@ -8,7 +8,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class SuffixTree { + private static final Logger LOGGER = LoggerFactory.getLogger(SuffixTree.class); + private static final String WORD_TERMINATION = "$"; private static final int POSITION_UNDEFINED = -1; private Node root; @@ -23,7 +25,7 @@ public class SuffixTree { } public List searchText(String pattern) { - LOGGER.info("Searching for pattern \"{}\"", pattern); + LOGGER.debug("Searching for pattern \"{}\"", pattern); List result = new ArrayList<>(); List nodes = getAllNodesInTraversePath(pattern, root, false); @@ -41,11 +43,11 @@ public class SuffixTree { } private void addSuffix(String suffix, int position) { - LOGGER.info(">>>>>>>>>>>> Adding new suffix {}", suffix); + LOGGER.debug(">>>>>>>>>>>> Adding new suffix {}", suffix); List nodes = getAllNodesInTraversePath(suffix, root, true); if (nodes.size() == 0) { addChildNode(root, suffix, position); - LOGGER.info("{}", printTree()); + LOGGER.debug("{}", printTree()); } else { Node lastNode = nodes.remove(nodes.size() - 1); String newText = suffix; @@ -58,7 +60,7 @@ public class SuffixTree { newText = newText.substring(existingSuffixUptoLastNode.length()); } extendNode(lastNode, newText, position); - LOGGER.info("{}", printTree()); + LOGGER.debug("{}", printTree()); } } diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java index 715bb55fcb..7af25a85ca 100644 --- a/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/dfs/GraphUnitTest.java @@ -2,7 +2,6 @@ package com.baeldung.algorithms.dfs; import java.util.List; -import com.baeldung.algorithms.dfs.Graph; import org.junit.Test; public class GraphUnitTest { diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/quadtree/QuadTreeSearchUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/quadtree/QuadTreeSearchUnitTest.java index 0b58ae9f14..faf06ced31 100644 --- a/algorithms-searching/src/test/java/com/baeldung/algorithms/quadtree/QuadTreeSearchUnitTest.java +++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/quadtree/QuadTreeSearchUnitTest.java @@ -10,7 +10,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class QuadTreeSearchUnitTest { - + private static final Logger LOGGER = LoggerFactory.getLogger(QuadTreeSearchUnitTest.class); private static QuadTree quadTree; @@ -20,41 +20,41 @@ public class QuadTreeSearchUnitTest { Region area = new Region(0, 0, 400, 400); quadTree = new QuadTree(area); - float[][] points = new float[][] { { 21, 25 }, { 55, 53 }, { 70, 318 }, { 98, 302 }, + float[][] points = new float[][] { { 21, 25 }, { 55, 53 }, { 70, 318 }, { 98, 302 }, { 49, 229 }, { 135, 229 }, { 224, 292 }, { 206, 321 }, { 197, 258 }, { 245, 238 } }; for (int i = 0; i < points.length; i++) { Point point = new Point(points[i][0], points[i][1]); quadTree.addPoint(point); } - LOGGER.info("\n" + quadTree.printTree("")); - LOGGER.info("=============================================="); + LOGGER.debug("\n" + quadTree.printTree("")); + LOGGER.debug("=============================================="); } @Test public void givenQuadTree_whenSearchingForRange_thenReturn1MatchingItem() { Region searchArea = new Region(200, 200, 250, 250); List result = quadTree.search(searchArea, null, ""); - LOGGER.info(result.toString()); - LOGGER.info(quadTree.printSearchTraversePath()); - + LOGGER.debug(result.toString()); + LOGGER.debug(quadTree.printSearchTraversePath()); + Assert.assertEquals(1, result.size()); - Assert.assertArrayEquals(new float[] { 245, 238 }, + Assert.assertArrayEquals(new float[] { 245, 238 }, new float[]{result.get(0).getX(), result.get(0).getY() }, 0); } - + @Test public void givenQuadTree_whenSearchingForRange_thenReturn2MatchingItems() { Region searchArea = new Region(0, 0, 100, 100); List result = quadTree.search(searchArea, null, ""); - LOGGER.info(result.toString()); - LOGGER.info(quadTree.printSearchTraversePath()); - + LOGGER.debug(result.toString()); + LOGGER.debug(quadTree.printSearchTraversePath()); + Assert.assertEquals(2, result.size()); - Assert.assertArrayEquals(new float[] { 21, 25 }, + Assert.assertArrayEquals(new float[] { 21, 25 }, new float[]{result.get(0).getX(), result.get(0).getY() }, 0); - Assert.assertArrayEquals(new float[] { 55, 53 }, + Assert.assertArrayEquals(new float[] { 55, 53 }, new float[]{result.get(1).getX(), result.get(1).getY() }, 0); - + } } diff --git a/apache-libraries/src/main/resources/log4j2.xml b/apache-libraries/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..d1ea5173fa --- /dev/null +++ b/apache-libraries/src/main/resources/log4j2.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apache-spark/src/main/resources/log4j.properties b/apache-spark/src/main/resources/log4j.properties new file mode 100644 index 0000000000..07a2943655 --- /dev/null +++ b/apache-spark/src/main/resources/log4j.properties @@ -0,0 +1,42 @@ +# +# 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. +# + +# Set everything to be logged to the console +log4j.rootCategory=WARN, console +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.target=System.err +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n + +# Set the default spark-shell log level to WARN. When running the spark-shell, the +# log level for this class is used to overwrite the root logger's log level, so that +# the user can have different defaults for the shell and regular Spark apps. +log4j.logger.org.apache.spark.repl.Main=WARN + +# Settings to quiet third party logs that are too verbose +log4j.logger.org.spark_project.jetty=WARN +log4j.logger.org.spark_project.jetty.util.component.AbstractLifeCycle=ERROR +log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO +log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO + +# SPARK-9183: Settings to avoid annoying messages when looking up nonexistent UDFs in SparkSQL with Hive support +log4j.logger.org.apache.hadoop.hive.metastore.RetryingHMSHandler=FATAL +log4j.logger.org.apache.hadoop.hive.ql.exec.FunctionRegistry=ERROR + +# Parquet related logging +log4j.logger.org.apache.parquet.CorruptStatistics=ERROR +log4j.logger.parquet.CorruptStatistics=ERROR diff --git a/core-java-modules/core-java-io/src/main/resources/logback.xml b/core-java-modules/core-java-io/src/main/resources/logback.xml index 56af2d397e..617917dca2 100644 --- a/core-java-modules/core-java-io/src/main/resources/logback.xml +++ b/core-java-modules/core-java-io/src/main/resources/logback.xml @@ -9,6 +9,7 @@ + diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index b638f81b0c..ae2333d721 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -76,6 +76,7 @@ org.apache.maven.plugins maven-dependency-plugin + ${maven-dependency-plugin.version} copy-dependencies @@ -106,6 +107,7 @@ org.apache.maven.plugins maven-assembly-plugin + ${maven-assembly-plugin.version} package @@ -383,6 +385,8 @@ 3.0.2 1.4.4 3.1.1 + 3.3.0 + 3.2.0 2.0.3.RELEASE 1.8 1.8 diff --git a/jee-7/src/main/resources/logback.xml b/jee-7/src/main/resources/logback.xml index 7d900d8ea8..5c1b7ec771 100644 --- a/jee-7/src/main/resources/logback.xml +++ b/jee-7/src/main/resources/logback.xml @@ -7,6 +7,8 @@ + + diff --git a/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties index 3829f676d3..d7fb13da08 100644 --- a/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa-crud/src/main/resources/application.properties @@ -1,7 +1,6 @@ spring.jpa.properties.hibernate.jdbc.batch_size=4 spring.jpa.properties.hibernate.order_inserts=true spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.generate_statistics=true spring.jpa.database-platform=org.hibernate.dialect.H2Dialect diff --git a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java index 7ddf36d3f0..f91c966e94 100644 --- a/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-crud/src/test/java/com/baeldung/batchinserts/BatchInsertIntegrationTest.java @@ -9,6 +9,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -20,6 +21,7 @@ import com.baeldung.boot.web.controllers.CustomerController; @RunWith(SpringRunner.class) @SpringBootTest(classes=Application.class) @AutoConfigureMockMvc +@ActiveProfiles("stats") public class BatchInsertIntegrationTest { @Autowired @@ -35,6 +37,6 @@ public class BatchInsertIntegrationTest { public void whenInsertingCustomers_thenCustomersAreCreated() throws Exception { this.mockMvc.perform(post("/customers")) .andExpect(status().isOk()); - } - + } + } \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties index 4141f5668e..bc9c9a832c 100644 --- a/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties +++ b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-batchinserts.properties @@ -3,4 +3,6 @@ spring.jpa.show-sql=false spring.jpa.properties.hibernate.jdbc.batch_size=5 spring.jpa.properties.hibernate.order_inserts=true spring.jpa.properties.hibernate.order_updates=true -spring.jpa.properties.hibernate.batch_versioned_data=true \ No newline at end of file +spring.jpa.properties.hibernate.batch_versioned_data=true + +spring.jpa.properties.hibernate.generate_statistics=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-crud/src/test/resources/application-stats.properties b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-stats.properties new file mode 100644 index 0000000000..97bc170ca0 --- /dev/null +++ b/persistence-modules/spring-data-jpa-crud/src/test/resources/application-stats.properties @@ -0,0 +1,5 @@ +spring.jpa.properties.hibernate.jdbc.batch_size=4 +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true + +spring.jpa.properties.hibernate.generate_statistics=true \ No newline at end of file