Skip to content

Commit d7e298b

Browse files
author
mikr
committed
JAVA-7244 Review log statements for projects
1 parent 5e4c5a4 commit d7e298b

34 files changed

Lines changed: 378 additions & 21 deletions

File tree

algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/caesarcipher/CaesarCipher.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.baeldung.algorithms.caesarcipher;
22

33
import org.apache.commons.math3.stat.inference.ChiSquareTest;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46

57
import java.util.Arrays;
68
import java.util.stream.IntStream;
79

810
public class CaesarCipher {
11+
12+
private final Logger log = LoggerFactory.getLogger(CaesarCipher.class);
13+
914
private static final char LETTER_A = 'a';
1015
private static final char LETTER_Z = 'z';
1116
private static final int ALPHABET_SIZE = LETTER_Z - LETTER_A + 1;
@@ -72,7 +77,7 @@ private double[] expectedLettersFrequencies(int messageLength) {
7277
private int probableOffset(double[] chiSquares) {
7378
int probableOffset = 0;
7479
for (int offset = 0; offset < chiSquares.length; offset++) {
75-
System.out.println(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset]));
80+
log.debug(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset]));
7681
if (chiSquares[offset] < chiSquares[probableOffset]) {
7782
probableOffset = offset;
7883
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>

algorithms-searching/src/main/java/com/baeldung/algorithms/breadthfirstsearch/BreadthFirstSearchAlgorithm.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static <T> Optional<Tree<T>> search(T value, Tree<T> root) {
1616
Tree<T> currentNode;
1717
while (!queue.isEmpty()) {
1818
currentNode = queue.remove();
19-
LOGGER.info("Visited node with value: {}", currentNode.getValue());
19+
LOGGER.debug("Visited node with value: {}", currentNode.getValue());
2020

2121
if (currentNode.getValue().equals(value)) {
2222
return Optional.of(currentNode);
@@ -37,7 +37,7 @@ public static <T> Optional<Node<T>> search(T value, Node<T> start) {
3737

3838
while (!queue.isEmpty()) {
3939
currentNode = queue.remove();
40-
LOGGER.info("Visited node with value: {}", currentNode.getValue());
40+
LOGGER.debug("Visited node with value: {}", currentNode.getValue());
4141

4242
if (currentNode.getValue().equals(value)) {
4343
return Optional.of(currentNode);

algorithms-searching/src/main/java/com/baeldung/algorithms/suffixtree/SuffixTree.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public SuffixTree(String text) {
2323
}
2424

2525
public List<String> searchText(String pattern) {
26-
LOGGER.info("Searching for pattern \"{}\"", pattern);
26+
LOGGER.debug("Searching for pattern \"{}\"", pattern);
2727
List<String> result = new ArrayList<>();
2828
List<Node> nodes = getAllNodesInTraversePath(pattern, root, false);
2929

@@ -41,11 +41,11 @@ public List<String> searchText(String pattern) {
4141
}
4242

4343
private void addSuffix(String suffix, int position) {
44-
LOGGER.info(">>>>>>>>>>>> Adding new suffix {}", suffix);
44+
LOGGER.debug(">>>>>>>>>>>> Adding new suffix {}", suffix);
4545
List<Node> nodes = getAllNodesInTraversePath(suffix, root, true);
4646
if (nodes.size() == 0) {
4747
addChildNode(root, suffix, position);
48-
LOGGER.info("{}", printTree());
48+
LOGGER.debug("{}", printTree());
4949
} else {
5050
Node lastNode = nodes.remove(nodes.size() - 1);
5151
String newText = suffix;
@@ -58,7 +58,7 @@ private void addSuffix(String suffix, int position) {
5858
newText = newText.substring(existingSuffixUptoLastNode.length());
5959
}
6060
extendNode(lastNode, newText, position);
61-
LOGGER.info("{}", printTree());
61+
LOGGER.debug("{}", printTree());
6262
}
6363
}
6464

algorithms-searching/src/test/java/com/baeldung/algorithms/quadtree/QuadTreeSearchUnitTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ public static void setUp() {
2727
Point point = new Point(points[i][0], points[i][1]);
2828
quadTree.addPoint(point);
2929
}
30-
LOGGER.info("\n" + quadTree.printTree(""));
31-
LOGGER.info("==============================================");
30+
LOGGER.debug("\n" + quadTree.printTree(""));
31+
LOGGER.debug("==============================================");
3232
}
3333

3434
@Test
3535
public void givenQuadTree_whenSearchingForRange_thenReturn1MatchingItem() {
3636
Region searchArea = new Region(200, 200, 250, 250);
3737
List<Point> result = quadTree.search(searchArea, null, "");
38-
LOGGER.info(result.toString());
39-
LOGGER.info(quadTree.printSearchTraversePath());
38+
LOGGER.debug(result.toString());
39+
LOGGER.debug(quadTree.printSearchTraversePath());
4040

4141
Assert.assertEquals(1, result.size());
4242
Assert.assertArrayEquals(new float[] { 245, 238 },
@@ -47,8 +47,8 @@ public void givenQuadTree_whenSearchingForRange_thenReturn1MatchingItem() {
4747
public void givenQuadTree_whenSearchingForRange_thenReturn2MatchingItems() {
4848
Region searchArea = new Region(0, 0, 100, 100);
4949
List<Point> result = quadTree.search(searchArea, null, "");
50-
LOGGER.info(result.toString());
51-
LOGGER.info(quadTree.printSearchTraversePath());
50+
LOGGER.debug(result.toString());
51+
LOGGER.debug(quadTree.printSearchTraversePath());
5252

5353
Assert.assertEquals(2, result.size());
5454
Assert.assertArrayEquals(new float[] { 21, 25 },

algorithms-searching/src/test/java/com/baeldung/algorithms/suffixtree/SuffixTreeUnitTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,54 +24,54 @@ public static void setUp() {
2424
public void givenSuffixTree_whenSearchingForA_thenReturn6Matches() {
2525
List<String> matches = suffixTree.searchText("a");
2626
matches.stream()
27-
.forEach(m -> LOGGER.info(m));
27+
.forEach(m -> LOGGER.debug(m));
2828
Assert.assertArrayEquals(new String[] { "h[a]vanabanana", "hav[a]nabanana", "havan[a]banana", "havanab[a]nana", "havanaban[a]na", "havanabanan[a]" }, matches.toArray());
2929
}
3030

3131
@Test
3232
public void givenSuffixTree_whenSearchingForNab_thenReturn1Match() {
3333
List<String> matches = suffixTree.searchText("nab");
3434
matches.stream()
35-
.forEach(m -> LOGGER.info(m));
35+
.forEach(m -> LOGGER.debug(m));
3636
Assert.assertArrayEquals(new String[] { "hava[nab]anana" }, matches.toArray());
3737
}
3838

3939
@Test
4040
public void givenSuffixTree_whenSearchingForNag_thenReturnNoMatches() {
4141
List<String> matches = suffixTree.searchText("nag");
4242
matches.stream()
43-
.forEach(m -> LOGGER.info(m));
43+
.forEach(m -> LOGGER.debug(m));
4444
Assert.assertArrayEquals(new String[] {}, matches.toArray());
4545
}
4646

4747
@Test
4848
public void givenSuffixTree_whenSearchingForBanana_thenReturn2Matches() {
4949
List<String> matches = suffixTree.searchText("ana");
5050
matches.stream()
51-
.forEach(m -> LOGGER.info(m));
51+
.forEach(m -> LOGGER.debug(m));
5252
Assert.assertArrayEquals(new String[] { "hav[ana]banana", "havanab[ana]na", "havanaban[ana]" }, matches.toArray());
5353
}
5454

5555
@Test
5656
public void givenSuffixTree_whenSearchingForNa_thenReturn4Matches() {
5757
List<String> matches = suffixTree.searchText("na");
5858
matches.stream()
59-
.forEach(m -> LOGGER.info(m));
59+
.forEach(m -> LOGGER.debug(m));
6060
Assert.assertArrayEquals(new String[] { "hava[na]banana", "havanaba[na]na", "havanabana[na]" }, matches.toArray());
6161
}
6262

6363
@Test
6464
public void givenSuffixTree_whenSearchingForX_thenReturnNoMatches() {
6565
List<String> matches = suffixTree.searchText("x");
6666
matches.stream()
67-
.forEach(m -> LOGGER.info(m));
67+
.forEach(m -> LOGGER.debug(m));
6868
Assert.assertArrayEquals(new String[] {}, matches.toArray());
6969
}
7070

7171
private static void printTree() {
7272
suffixTree.printTree();
7373

74-
LOGGER.info("\n" + suffixTree.printTree());
75-
LOGGER.info("==============================================");
74+
LOGGER.debug("\n" + suffixTree.printTree());
75+
LOGGER.debug("==============================================");
7676
}
7777
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>

0 commit comments

Comments
 (0)