Java-1457 Reduce logging - Modules jgit, libraries-testing (#9884)

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

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

Co-authored-by: mikr <michael.krimgen@ximedes.com>
This commit is contained in:
Maiklins 2020-08-18 13:46:29 +02:00 committed by GitHub
parent e4f034795d
commit afd00056a2
6 changed files with 40 additions and 17 deletions

View File

@ -6,6 +6,8 @@ import com.baeldung.jgit.helper.Helper;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository; 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 * Simple snippet which shows how to add a file to the index
@ -14,6 +16,8 @@ import org.eclipse.jgit.lib.Repository;
*/ */
public class AddFile { public class AddFile {
private static final Logger logger = LoggerFactory.getLogger(AddFile.class);
public static void main(String[] args) throws IOException, GitAPIException { public static void main(String[] args) throws IOException, GitAPIException {
// prepare a new test-repository // prepare a new test-repository
try (Repository repository = Helper.createNewRepository()) { try (Repository repository = Helper.createNewRepository()) {
@ -29,7 +33,7 @@ public class AddFile {
.addFilepattern("testfile") .addFilepattern("testfile")
.call(); .call();
System.out.println("Added file " + myfile + " to repository at " + repository.getDirectory()); logger.debug("Added file " + myfile + " to repository at " + repository.getDirectory());
} }
} }
} }

View File

@ -7,6 +7,8 @@ import com.baeldung.jgit.helper.Helper;
import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Simple snippet which shows how to commit all files * Simple snippet which shows how to commit all files
@ -15,6 +17,8 @@ import org.eclipse.jgit.lib.Repository;
*/ */
public class CommitAll { public class CommitAll {
private static final Logger logger = LoggerFactory.getLogger(CommitAll.class);
public static void main(String[] args) throws IOException, GitAPIException { public static void main(String[] args) throws IOException, GitAPIException {
// prepare a new test-repository // prepare a new test-repository
try (Repository repository = Helper.createNewRepository()) { try (Repository repository = Helper.createNewRepository()) {
@ -44,7 +48,7 @@ public class CommitAll {
.call(); .call();
System.out.println("Committed all changes to repository at " + repository.getDirectory()); logger.debug("Committed all changes to repository at " + repository.getDirectory());
} }
} }
} }

View File

@ -9,6 +9,8 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Simple snippet which shows how to create a tag * Simple snippet which shows how to create a tag
@ -17,6 +19,8 @@ import org.eclipse.jgit.revwalk.RevWalk;
*/ */
public class CreateAndDeleteTag { public class CreateAndDeleteTag {
private static final Logger logger = LoggerFactory.getLogger(CreateAndDeleteTag.class);
public static void main(String[] args) throws IOException, GitAPIException { public static void main(String[] args) throws IOException, GitAPIException {
// prepare test-repository // prepare test-repository
try (Repository repository = Helper.openJGitRepository()) { try (Repository repository = Helper.openJGitRepository()) {
@ -26,7 +30,7 @@ public class CreateAndDeleteTag {
// set it on the current HEAD // set it on the current HEAD
Ref tag = git.tag().setName("tag_for_testing").call(); 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 // remove the tag again
git.tagDelete().setTags("tag_for_testing").call(); git.tagDelete().setTags("tag_for_testing").call();
@ -36,14 +40,14 @@ public class CreateAndDeleteTag {
try (RevWalk walk = new RevWalk(repository)) { try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(id); RevCommit commit = walk.parseCommit(id);
tag = git.tag().setObjectId(commit).setName("tag_for_testing").call(); 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 // remove the tag again
git.tagDelete().setTags("tag_for_testing").call(); git.tagDelete().setTags("tag_for_testing").call();
// create an annotated tag // create an annotated tag
tag = git.tag().setName("tag_for_testing").setAnnotated(true).call(); 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 // remove the tag again
git.tagDelete().setTags("tag_for_testing").call(); git.tagDelete().setTags("tag_for_testing").call();

View File

@ -7,6 +7,9 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit; 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. * Simple snippet which shows how to get the commit-ids for a file to provide log information.
* *
@ -14,6 +17,8 @@ import org.eclipse.jgit.revwalk.RevCommit;
*/ */
public class Log { public class Log {
private static final Logger logger = LoggerFactory.getLogger(Log.class);
@SuppressWarnings("unused") @SuppressWarnings("unused")
public static void main(String[] args) throws IOException, GitAPIException { public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = Helper.openJGitRepository()) { try (Repository repository = Helper.openJGitRepository()) {
@ -22,30 +27,30 @@ public class Log {
.call(); .call();
int count = 0; int count = 0;
for (RevCommit rev : logs) { 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++; count++;
} }
System.out.println("Had " + count + " commits overall on current branch"); logger.debug("Had " + count + " commits overall on current branch");
logs = git.log() logs = git.log()
.add(repository.resolve(git.getRepository().getFullBranch())) .add(repository.resolve(git.getRepository().getFullBranch()))
.call(); .call();
count = 0; count = 0;
for (RevCommit rev : logs) { 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++; 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() logs = git.log()
.all() .all()
.call(); .call();
count = 0; count = 0;
for (RevCommit rev : logs) { 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++; count++;
} }
System.out.println("Had " + count + " commits overall in repository"); logger.debug("Had " + count + " commits overall in repository");
logs = git.log() logs = git.log()
// for all log.all() // for all log.all()
@ -53,10 +58,10 @@ public class Log {
.call(); .call();
count = 0; count = 0;
for (RevCommit rev : logs) { 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++; count++;
} }
System.out.println("Had " + count + " commits on README.md"); logger.debug("Had " + count + " commits on README.md");
logs = git.log() logs = git.log()
// for all log.all() // for all log.all()
@ -64,10 +69,10 @@ public class Log {
.call(); .call();
count = 0; count = 0;
for (RevCommit rev : logs) { 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++; count++;
} }
System.out.println("Had " + count + " commits on pom.xml"); logger.debug("Had " + count + " commits on pom.xml");
} }
} }
} }

View File

@ -11,7 +11,8 @@ public class PorcelainUnitTest {
CommitAll.main(null); CommitAll.main(null);
CreateAndDeleteTag.main(null); CreateAndDeleteTag.main(null);
Log.main(null); Log.main(null);
} }
} }

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.dbunit" level="INFO" />
</configuration>