Skip to content

Commit

Permalink
Java-1457 Reduce logging - Modules jgit, libraries-testing (eugenp#9884)
Browse files Browse the repository at this point in the history
* Java-1457 Reduce logging - Modules jgit, libraries-testing

* Java-1457 Reduce logging - Modules jgit, libraries-testing

Co-authored-by: mikr <[email protected]>
  • Loading branch information
Maiklins and mikr authored Aug 18, 2020
1 parent 21d4854 commit 0aa3c0d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
6 changes: 5 additions & 1 deletion jgit/src/main/java/com/baeldung/jgit/porcelain/AddFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple snippet which shows how to add a file to the index
Expand All @@ -14,6 +16,8 @@
*/
public class AddFile {

private static final Logger logger = LoggerFactory.getLogger(AddFile.class);

public static void main(String[] args) throws IOException, GitAPIException {
// prepare a new test-repository
try (Repository repository = Helper.createNewRepository()) {
Expand All @@ -29,7 +33,7 @@ public static void main(String[] args) throws IOException, GitAPIException {
.addFilepattern("testfile")
.call();

System.out.println("Added file " + myfile + " to repository at " + repository.getDirectory());
logger.debug("Added file " + myfile + " to repository at " + repository.getDirectory());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple snippet which shows how to commit all files
Expand All @@ -15,6 +17,8 @@
*/
public class CommitAll {

private static final Logger logger = LoggerFactory.getLogger(CommitAll.class);

public static void main(String[] args) throws IOException, GitAPIException {
// prepare a new test-repository
try (Repository repository = Helper.createNewRepository()) {
Expand Down Expand Up @@ -44,7 +48,7 @@ public static void main(String[] args) throws IOException, GitAPIException {
.call();


System.out.println("Committed all changes to repository at " + repository.getDirectory());
logger.debug("Committed all changes to repository at " + repository.getDirectory());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple snippet which shows how to create a tag
Expand All @@ -17,6 +19,8 @@
*/
public class CreateAndDeleteTag {

private static final Logger logger = LoggerFactory.getLogger(CreateAndDeleteTag.class);

public static void main(String[] args) throws IOException, GitAPIException {
// prepare test-repository
try (Repository repository = Helper.openJGitRepository()) {
Expand All @@ -26,7 +30,7 @@ public static void main(String[] args) throws IOException, GitAPIException {

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

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

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

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

// remove the tag again
git.tagDelete().setTags("tag_for_testing").call();
Expand Down
25 changes: 15 additions & 10 deletions jgit/src/main/java/com/baeldung/jgit/porcelain/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Simple snippet which shows how to get the commit-ids for a file to provide log information.
*
*
*/
public class Log {

private static final Logger logger = LoggerFactory.getLogger(Log.class);

@SuppressWarnings("unused")
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = Helper.openJGitRepository()) {
Expand All @@ -22,52 +27,52 @@ public static void main(String[] args) throws IOException, GitAPIException {
.call();
int count = 0;
for (RevCommit rev : logs) {
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits overall on current branch");
logger.debug("Had " + count + " commits overall on current branch");

logs = git.log()
.add(repository.resolve(git.getRepository().getFullBranch()))
.call();
count = 0;
for (RevCommit rev : logs) {
System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits overall on "+git.getRepository().getFullBranch());
logger.debug("Had " + count + " commits overall on "+git.getRepository().getFullBranch());

logs = git.log()
.all()
.call();
count = 0;
for (RevCommit rev : logs) {
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits overall in repository");
logger.debug("Had " + count + " commits overall in repository");

logs = git.log()
// for all log.all()
.addPath("README.md")
.call();
count = 0;
for (RevCommit rev : logs) {
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits on README.md");
logger.debug("Had " + count + " commits on README.md");

logs = git.log()
// for all log.all()
.addPath("pom.xml")
.call();
count = 0;
for (RevCommit rev : logs) {
//System.out.println("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
logger.trace("Commit: " + rev /* + ", name: " + rev.getName() + ", id: " + rev.getId().getName() */);
count++;
}
System.out.println("Had " + count + " commits on pom.xml");
logger.debug("Had " + count + " commits on pom.xml");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public void runSamples() throws Exception {
CommitAll.main(null);

CreateAndDeleteTag.main(null);

Log.main(null);

Log.main(null);

}
}
5 changes: 5 additions & 0 deletions libraries-testing/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.dbunit" level="INFO" />
</configuration>

0 comments on commit 0aa3c0d

Please sign in to comment.