Skip to content

Commit afd0005

Browse files
Maiklinsmikr
andauthored
Java-1457 Reduce logging - Modules jgit, libraries-testing (eugenp#9884)
* Java-1457 Reduce logging - Modules jgit, libraries-testing * Java-1457 Reduce logging - Modules jgit, libraries-testing Co-authored-by: mikr <[email protected]>
1 parent e4f0347 commit afd0005

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

jgit/src/main/java/com/baeldung/jgit/porcelain/AddFile.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import org.eclipse.jgit.api.Git;
77
import org.eclipse.jgit.api.errors.GitAPIException;
88
import org.eclipse.jgit.lib.Repository;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
911

1012
/**
1113
* Simple snippet which shows how to add a file to the index
@@ -14,6 +16,8 @@
1416
*/
1517
public class AddFile {
1618

19+
private static final Logger logger = LoggerFactory.getLogger(AddFile.class);
20+
1721
public static void main(String[] args) throws IOException, GitAPIException {
1822
// prepare a new test-repository
1923
try (Repository repository = Helper.createNewRepository()) {
@@ -29,7 +33,7 @@ public static void main(String[] args) throws IOException, GitAPIException {
2933
.addFilepattern("testfile")
3034
.call();
3135

32-
System.out.println("Added file " + myfile + " to repository at " + repository.getDirectory());
36+
logger.debug("Added file " + myfile + " to repository at " + repository.getDirectory());
3337
}
3438
}
3539
}

jgit/src/main/java/com/baeldung/jgit/porcelain/CommitAll.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.eclipse.jgit.api.Git;
88
import org.eclipse.jgit.api.errors.GitAPIException;
99
import org.eclipse.jgit.lib.Repository;
10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
1012

1113
/**
1214
* Simple snippet which shows how to commit all files
@@ -15,6 +17,8 @@
1517
*/
1618
public class CommitAll {
1719

20+
private static final Logger logger = LoggerFactory.getLogger(CommitAll.class);
21+
1822
public static void main(String[] args) throws IOException, GitAPIException {
1923
// prepare a new test-repository
2024
try (Repository repository = Helper.createNewRepository()) {
@@ -44,7 +48,7 @@ public static void main(String[] args) throws IOException, GitAPIException {
4448
.call();
4549

4650

47-
System.out.println("Committed all changes to repository at " + repository.getDirectory());
51+
logger.debug("Committed all changes to repository at " + repository.getDirectory());
4852
}
4953
}
5054
}

jgit/src/main/java/com/baeldung/jgit/porcelain/CreateAndDeleteTag.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.eclipse.jgit.lib.Repository;
1010
import org.eclipse.jgit.revwalk.RevCommit;
1111
import org.eclipse.jgit.revwalk.RevWalk;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

1315
/**
1416
* Simple snippet which shows how to create a tag
@@ -17,6 +19,8 @@
1719
*/
1820
public class CreateAndDeleteTag {
1921

22+
private static final Logger logger = LoggerFactory.getLogger(CreateAndDeleteTag.class);
23+
2024
public static void main(String[] args) throws IOException, GitAPIException {
2125
// prepare test-repository
2226
try (Repository repository = Helper.openJGitRepository()) {
@@ -26,7 +30,7 @@ public static void main(String[] args) throws IOException, GitAPIException {
2630

2731
// set it on the current HEAD
2832
Ref tag = git.tag().setName("tag_for_testing").call();
29-
System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
33+
logger.debug("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
3034

3135
// remove the tag again
3236
git.tagDelete().setTags("tag_for_testing").call();
@@ -36,14 +40,14 @@ public static void main(String[] args) throws IOException, GitAPIException {
3640
try (RevWalk walk = new RevWalk(repository)) {
3741
RevCommit commit = walk.parseCommit(id);
3842
tag = git.tag().setObjectId(commit).setName("tag_for_testing").call();
39-
System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
43+
logger.debug("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
4044

4145
// remove the tag again
4246
git.tagDelete().setTags("tag_for_testing").call();
4347

4448
// create an annotated tag
4549
tag = git.tag().setName("tag_for_testing").setAnnotated(true).call();
46-
System.out.println("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
50+
logger.debug("Created/moved tag " + tag + " to repository at " + repository.getDirectory());
4751

4852
// remove the tag again
4953
git.tagDelete().setTags("tag_for_testing").call();

jgit/src/main/java/com/baeldung/jgit/porcelain/Log.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77
import org.eclipse.jgit.lib.Repository;
88
import org.eclipse.jgit.revwalk.RevCommit;
99

10+
import org.slf4j.Logger;
11+
import org.slf4j.LoggerFactory;
12+
1013
/**
1114
* Simple snippet which shows how to get the commit-ids for a file to provide log information.
1215
*
1316
*
1417
*/
1518
public class Log {
1619

20+
private static final Logger logger = LoggerFactory.getLogger(Log.class);
21+
1722
@SuppressWarnings("unused")
1823
public static void main(String[] args) throws IOException, GitAPIException {
1924
try (Repository repository = Helper.openJGitRepository()) {
@@ -22,52 +27,52 @@ public static void main(String[] args) throws IOException, GitAPIException {
2227
.call();
2328
int count = 0;
2429
for (RevCommit rev : logs) {
25-
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
30+
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
2631
count++;
2732
}
28-
System.out.println("Had " + count + " commits overall on current branch");
33+
logger.debug("Had " + count + " commits overall on current branch");
2934

3035
logs = git.log()
3136
.add(repository.resolve(git.getRepository().getFullBranch()))
3237
.call();
3338
count = 0;
3439
for (RevCommit rev : logs) {
35-
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
40+
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
3641
count++;
3742
}
38-
System.out.println("Had " + count + " commits overall on "+git.getRepository().getFullBranch());
43+
logger.debug("Had " + count + " commits overall on "+git.getRepository().getFullBranch());
3944

4045
logs = git.log()
4146
.all()
4247
.call();
4348
count = 0;
4449
for (RevCommit rev : logs) {
45-
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
50+
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
4651
count++;
4752
}
48-
System.out.println("Had " + count + " commits overall in repository");
53+
logger.debug("Had " + count + " commits overall in repository");
4954

5055
logs = git.log()
5156
// for all log.all()
5257
.addPath("README.md")
5358
.call();
5459
count = 0;
5560
for (RevCommit rev : logs) {
56-
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
61+
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
5762
count++;
5863
}
59-
System.out.println("Had " + count + " commits on README.md");
64+
logger.debug("Had " + count + " commits on README.md");
6065

6166
logs = git.log()
6267
// for all log.all()
6368
.addPath("pom.xml")
6469
.call();
6570
count = 0;
6671
for (RevCommit rev : logs) {
67-
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
72+
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
6873
count++;
6974
}
70-
System.out.println("Had " + count + " commits on pom.xml");
75+
logger.debug("Had " + count + " commits on pom.xml");
7176
}
7277
}
7378
}

jgit/src/test/java/com/baeldung/jgit/porcelain/PorcelainUnitTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public void runSamples() throws Exception {
1111
CommitAll.main(null);
1212

1313
CreateAndDeleteTag.main(null);
14-
15-
Log.main(null);
14+
15+
Log.main(null);
16+
1617
}
1718
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<logger name="org.dbunit" level="INFO" />
4+
</configuration>
5+

0 commit comments

Comments
 (0)