Harmonize logging string for repositories

This commit is contained in:
René Pfeuffer
2020-12-03 09:39:25 +01:00
parent e6a658d3cc
commit eaf59f91c4
32 changed files with 102 additions and 93 deletions

View File

@@ -151,7 +151,7 @@ public class GitRepositoryConfigResource {
ConfigurationStore<GitRepositoryConfig> repositoryConfigStore = getStore(repository);
GitRepositoryConfig config = repositoryConfigMapper.map(dto);
repositoryConfigStore.set(config);
LOG.info("git default branch of repository {} has changed, sending clear cache event", repository.getNamespaceAndName());
LOG.info("git default branch of repository {} has changed, sending clear cache event", repository);
return Response.noContent().build();
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository;
import com.google.common.annotations.VisibleForTesting;
@@ -38,16 +38,16 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Executes git gc on every git repository. Statistics of the gc process are logged to the info level. The task is
* Executes git gc on every git repository. Statistics of the gc process are logged to the info level. The task is
* disabled by default and must be enabled through the global git configuration.
*
*
* @author Sebastian Sdorra
* @since 1.47
*/
public class GitGcTask implements Runnable {
private static final String SP = System.getProperty("line.seperator", "\n");
private static final Logger logger = LoggerFactory.getLogger(GitGcTask.class);
private final RepositoryManager repositoryManager;
@@ -74,19 +74,19 @@ public class GitGcTask implements Runnable {
{
if (repository.isValid() && repository.isHealthy())
{
logger.info("start git gc for repository {}", repository.getNamespaceAndName());
logger.info("start git gc for repository {}", repository);
Stopwatch sw = Stopwatch.createStarted();
gc(repository);
logger.debug("gc of repository {} has finished after {}", repository.getNamespaceAndName(), sw.stop());
}
else
{
logger.debug("skip non valid/healthy repository {}", repository.getNamespaceAndName());
logger.debug("gc of repository {} has finished after {}", repository, sw.stop());
}
}
else
else
{
logger.debug("skip non valid/healthy repository {}", repository);
}
}
else
{
logger.trace("skip non git repository {}", repository.getNamespaceAndName());
logger.trace("skip non git repository {}", repository);
}
}
@@ -123,31 +123,31 @@ public class GitGcTask implements Runnable {
// jgit returns the statistics after gc has finished
statistics(repository, gcc);
execute(repository, gcc);
}
catch (IOException ex)
}
catch (IOException ex)
{
logger.warn("failed to open git repository", ex);
}
}
catch (GitAPIException ex)
{
logger.warn("failed running git gc command", ex);
}
finally
finally
{
if (git != null){
git.close();
}
}
}
/**
* Opens the git repository. This method is only visible for testing purposes.
*
*
* @param file repository directory
*
*
* @return git for repository
*
* @throws IOException
*
* @throws IOException
*/
@VisibleForTesting
protected Git open(File file) throws IOException {

View File

@@ -134,7 +134,7 @@ public class GitBrowseCommand extends AbstractGitCommand
browserResult = new BrowserResult(revId.getName(), request.getRevision(), getEntry());
return browserResult;
} else {
logger.warn("could not find head of repository {}, empty?", repository.getNamespaceAndName());
logger.warn("could not find head of repository {}, empty?", repository);
return new BrowserResult(Constants.HEAD, request.getRevision(), createEmptyRoot());
}
}
@@ -209,7 +209,7 @@ public class GitBrowseCommand extends AbstractGitCommand
private void updateCache() {
request.updateCache(browserResult);
logger.info("updated browser result for repository {}", repository.getNamespaceAndName());
logger.info("updated browser result for repository {}", repository);
}
private FileObject getEntry() throws IOException {
@@ -330,7 +330,7 @@ public class GitBrowseCommand extends AbstractGitCommand
private Map<String, SubRepository> getSubRepositories()
throws IOException {
logger.debug("read submodules of {} at {}", repository.getName(), revId);
logger.debug("read submodules of {} at {}", repository, revId);
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
new GitCatCommand(context, lfsBlobStoreFactory).getContent(repo, revId, PATH_MODULES, baos);
@@ -375,7 +375,7 @@ public class GitBrowseCommand extends AbstractGitCommand
String oid = lfsPointer.getOid().getName();
Blob blob = lfsBlobStore.get(oid);
if (blob == null) {
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository.getNamespaceAndName());
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository);
file.setLength(null);
} else {
file.setLength(blob.getSize());

View File

@@ -142,7 +142,7 @@ public class GitCatCommand extends AbstractGitCommand implements CatCommand {
String oid = lfsPointer.getOid().getName();
Blob blob = lfsBlobStore.get(oid);
if (blob == null) {
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository.getNamespaceAndName());
logger.error("lfs blob for lob id {} not found in lfs store of repository {}", oid, repository);
throw notFound(entity("LFS", oid).in(repository));
}
GitUtil.release(revWalk);

View File

@@ -193,7 +193,7 @@ public class GitPullCommand extends AbstractGitPushOrPullCommand
private PullResponse pullFromUrl(PullCommandRequest request)
throws IOException {
logger.debug("pull changes from {} to {}", request.getRemoteUrl(), repository.getId());
logger.debug("pull changes from {} to {}", request.getRemoteUrl(), repository);
PullResponse response;
Git git = Git.wrap(open());

View File

@@ -80,7 +80,7 @@ public class GitPushCommand extends AbstractGitPushOrPullCommand
{
String remoteUrl = getRemoteUrl(request);
logger.debug("push changes from {} to {}", repository.getId(), remoteUrl);
logger.debug("push changes from {} to {}", repository, remoteUrl);
return new PushResponse(push(open(), remoteUrl));
}

View File

@@ -54,7 +54,7 @@ class GitWorkingCopyInitializer {
}
public ParentAndClone<Repository, Repository> initialize(File target, String initialBranch) {
LOG.trace("clone repository {}", context.getRepository().getId());
LOG.trace("clone repository {}", context.getRepository());
Stopwatch stopwatch = Stopwatch.createStarted();
try {
Repository clone = Git.cloneRepository()
@@ -78,7 +78,7 @@ class GitWorkingCopyInitializer {
} catch (GitAPIException | IOException e) {
throw new InternalRepositoryException(context.getRepository(), "could not clone working copy of repository", e);
} finally {
LOG.trace("took {} to clone repository {}", stopwatch.stop(), context.getRepository().getId());
LOG.trace("took {} to clone repository {}", stopwatch.stop(), context.getRepository());
}
}
}

View File

@@ -49,7 +49,7 @@ class GitWorkingCopyReclaimer {
}
public ParentAndClone<Repository, Repository> reclaim(File target, String initialBranch) throws SimpleWorkingCopyFactory.ReclaimFailedException {
LOG.trace("reclaim repository {}", context.getRepository().getId());
LOG.trace("reclaim repository {}", context.getRepository());
Stopwatch stopwatch = Stopwatch.createStarted();
Repository repo = openTarget(target);
try (Git git = Git.open(target)) {
@@ -63,7 +63,7 @@ class GitWorkingCopyReclaimer {
} catch (GitAPIException | IOException e) {
throw new SimpleWorkingCopyFactory.ReclaimFailedException(e);
} finally {
LOG.trace("took {} to reclaim repository {}", stopwatch.stop(), context.getRepository().getId());
LOG.trace("took {} to reclaim repository {}", stopwatch.stop(), context.getRepository());
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.web.lfs;
import org.eclipse.jgit.lfs.lib.AnyLongObjectId;
@@ -79,7 +79,7 @@ public class ScmBlobLfsRepository implements LargeFileRepository {
@Override
public ExpiringAction getDownloadAction(AnyLongObjectId id) {
if (accessToken == null) {
LOG.trace("create access token to download lfs object {} from repository {}", id, repository.getNamespaceAndName());
LOG.trace("create access token to download lfs object {} from repository {}", id, repository);
accessToken = tokenFactory.createReadAccessToken(repository);
}
return getAction(id, accessToken);
@@ -88,7 +88,7 @@ public class ScmBlobLfsRepository implements LargeFileRepository {
@Override
public ExpiringAction getUploadAction(AnyLongObjectId id, long size) {
if (accessToken == null) {
LOG.trace("create access token to upload lfs object {} to repository {}", id, repository.getNamespaceAndName());
LOG.trace("create access token to upload lfs object {} to repository {}", id, repository);
accessToken = tokenFactory.createWriteAccessToken(repository);
}
return getAction(id, accessToken);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.web.lfs.servlet;
import com.google.common.annotations.VisibleForTesting;
@@ -71,7 +71,7 @@ public class LfsServletFactory {
* @return The {@link LfsProtocolServlet} to provide the LFS Batch API for a SCM Repository.
*/
public LfsProtocolServlet createProtocolServletFor(Repository repository, HttpServletRequest request) {
LOG.trace("create lfs protocol servlet for repository {}", repository.getNamespaceAndName());
LOG.trace("create lfs protocol servlet for repository {}", repository);
BlobStore blobStore = lfsBlobStoreFactory.getLfsBlobStore(repository);
String baseUri = buildBaseUri(repository, request);
@@ -87,7 +87,7 @@ public class LfsServletFactory {
* @return The {@link FileLfsServlet} to provide the LFS Upload / Download API for a SCM Repository.
*/
public HttpServlet createFileLfsServletFor(Repository repository, HttpServletRequest request) {
LOG.trace("create lfs file servlet for repository {}", repository.getNamespaceAndName());
LOG.trace("create lfs file servlet for repository {}", repository);
return new ScmFileTransferServlet(lfsBlobStoreFactory.getLfsBlobStore(repository));
}