]> source.dussan.org Git - gitblit.git/commitdiff
Update some outdated, and sometimes wrong, logger format strings 1457/head
authorFlorian Zschocke <f.zschocke+git@gmail.com>
Mon, 23 Oct 2023 22:12:41 +0000 (00:12 +0200)
committerFlorian Zschocke <f.zschocke+git@gmail.com>
Mon, 23 Oct 2023 22:12:41 +0000 (00:12 +0200)
src/main/java/com/gitblit/service/FederationPullService.java
src/main/java/com/gitblit/service/GarbageCollectorService.java
src/main/java/com/gitblit/service/LuceneService.java
src/main/java/com/gitblit/service/MirrorService.java
src/main/java/com/gitblit/tickets/BranchTicketService.java
src/main/java/com/gitblit/tickets/FileTicketService.java
src/main/java/com/gitblit/tickets/ITicketService.java
src/main/java/com/gitblit/tickets/RedisTicketService.java
src/main/java/com/gitblit/tickets/TicketIndexer.java
src/main/java/com/gitblit/tickets/TicketNotifier.java

index 629cbf94c0eb552c2b64c29fd91ee3a0c470b688..3c9f0ed2a5b2cf1a778bbf5ea24195bf79407b40 100644 (file)
@@ -6,7 +6,6 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.InetAddress;
-import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -99,8 +98,7 @@ public abstract class FederationPullService implements Runnable {
                                FederationPullStatus is = registration.getLowestStatus();
                                if (is.ordinal() < was.ordinal()) {
                                        // the status for this registration has downgraded
-                                       logger.warn("Federation pull status of {0} is now {1}", registration.name,
-                                                       is.name());
+                                       logger.warn("Federation pull status of {} is now {}", registration.name, is.name());
                                        if (registration.notifyOnError) {
                                                String message = "Federation pull of " + registration.name + " @ "
                                                                + registration.url + " is now at " + is.name();
@@ -110,9 +108,7 @@ public abstract class FederationPullService implements Runnable {
                                        }
                                }
                        } catch (Throwable t) {
-                               logger.error(MessageFormat.format(
-                                               "Failed to pull from federated gitblit ({0} @ {1})", registration.name,
-                                               registration.url), t);
+                               logger.error("Failed to pull from federated gitblit ({} @ {})", registration.name, registration.url, t);
                        } finally {
                                reschedule(registration);
                        }
@@ -133,9 +129,8 @@ public abstract class FederationPullService implements Runnable {
                // confirm valid characters in server alias
                Character c = StringUtils.findInvalidCharacter(registrationFolder);
                if (c != null) {
-                       logger.error(MessageFormat
-                                       .format("Illegal character ''{0}'' in folder name ''{1}'' of federation registration {2}!",
-                                                       c, registrationFolder, registration.name));
+                       logger.error("Illegal character '{}' in folder name '{}' of federation registration {}!",
+                                                       c, registrationFolder, registration.name);
                        return;
                }
                File repositoriesFolder = gitblit.getRepositoriesFolder();
@@ -147,9 +142,8 @@ public abstract class FederationPullService implements Runnable {
                        String cloneUrl = entry.getKey();
                        RepositoryModel repository = entry.getValue();
                        if (!repository.hasCommits) {
-                               logger.warn(MessageFormat.format(
-                                               "Skipping federated repository {0} from {1} @ {2}. Repository is EMPTY.",
-                                               repository.name, registration.name, registration.url));
+                               logger.warn("Skipping federated repository {} from {} @ {}. Repository is EMPTY.",
+                                               repository.name, registration.name, registration.url);
                                registration.updateStatus(repository, FederationPullStatus.SKIPPED);
                                continue;
                        }
@@ -181,7 +175,7 @@ public abstract class FederationPullService implements Runnable {
                        Repository existingRepository = gitblit.getRepository(repositoryName);
 
                        if (existingRepository == null && gitblit.isCollectingGarbage(repositoryName)) {
-                               logger.warn(MessageFormat.format("Skipping local repository {0}, busy collecting garbage", repositoryName));
+                               logger.warn("Skipping local repository {}, busy collecting garbage", repositoryName);
                                continue;
                        }
 
@@ -196,9 +190,8 @@ public abstract class FederationPullService implements Runnable {
                                }
                                existingRepository.close();
                                if (!origin.startsWith(registration.url)) {
-                                       logger.warn(MessageFormat
-                                                       .format("Skipping federated repository {0} from {1} @ {2}. Origin does not match, consider EXCLUDING.",
-                                                                       repository.name, registration.name, registration.url));
+                                       logger.warn("Skipping federated repository {} from {} @ {}. Origin does not match, consider EXCLUDING.",
+                                                                       repository.name, registration.name, registration.url);
                                        registration.updateStatus(repository, FederationPullStatus.SKIPPED);
                                        continue;
                                }
@@ -207,8 +200,7 @@ public abstract class FederationPullService implements Runnable {
                        // clone/pull this repository
                        CredentialsProvider credentials = new UsernamePasswordCredentialsProvider(
                                        Constants.FEDERATION_USER, registration.token);
-                       logger.info(MessageFormat.format("Pulling federated repository {0} from {1} @ {2}",
-                                       repository.name, registration.name, registration.url));
+                       logger.info("Pulling federated repository {} from {} @ {}", repository.name, registration.name, registration.url);
 
                        CloneResult result = JGitUtils.cloneRepository(registrationFolderFile, repository.name,
                                        cloneUrl, registration.bare, credentials);
@@ -220,7 +212,7 @@ public abstract class FederationPullService implements Runnable {
                                repository.federationStrategy = FederationStrategy.EXCLUDE;
                                repository.isFrozen = registration.mirror;
                                repository.showRemoteBranches = !registration.mirror;
-                               logger.info(MessageFormat.format("     cloning {0}", repository.name));
+                               logger.info("     cloning {}", repository.name);
                                registration.updateStatus(repository, FederationPullStatus.MIRRORED);
                        } else {
                                // fetch and update
@@ -240,8 +232,7 @@ public abstract class FederationPullService implements Runnable {
                                                                String hash = ref.getReferencedObjectId().getName();
 
                                                                JGitUtils.setBranchRef(r, branch, hash);
-                                                               logger.info(MessageFormat.format("     resetting {0} of {1} to {2}", branch,
-                                                                               repository.name, hash));
+                                                               logger.info("     resetting {} of {} to {}", branch, repository.name, hash);
                                                        }
                                                }
 
@@ -252,8 +243,7 @@ public abstract class FederationPullService implements Runnable {
                                                        newHead = repository.HEAD;
                                                }
                                                JGitUtils.setHEADtoRef(r, newHead);
-                                               logger.info(MessageFormat.format("     resetting HEAD of {0} to {1}",
-                                                               repository.name, newHead));
+                                               logger.info("     resetting HEAD of {} to {}", repository.name, newHead);
                                                registration.updateStatus(repository, FederationPullStatus.MIRRORED);
                                        } else {
                                                // indicate no commits pulled
@@ -401,9 +391,7 @@ public abstract class FederationPullService implements Runnable {
                } catch (ForbiddenException e) {
                        // ignore forbidden exceptions
                } catch (IOException e) {
-                       logger.warn(MessageFormat.format(
-                                       "Failed to retrieve USERS from federated gitblit ({0} @ {1})",
-                                       registration.name, registration.url), e);
+                       logger.warn("Failed to retrieve USERS from federated gitblit ({} @ {})", registration.name, registration.url, e);
                }
 
                try {
@@ -422,9 +410,7 @@ public abstract class FederationPullService implements Runnable {
                } catch (ForbiddenException e) {
                        // ignore forbidden exceptions
                } catch (IOException e) {
-                       logger.warn(MessageFormat.format(
-                                       "Failed to retrieve TEAMS from federated gitblit ({0} @ {1})",
-                                       registration.name, registration.url), e);
+                       logger.warn("Failed to retrieve TEAMS from federated gitblit ({} @ {})", registration.name, registration.url, e);
                }
 
                try {
@@ -441,9 +427,7 @@ public abstract class FederationPullService implements Runnable {
                } catch (ForbiddenException e) {
                        // ignore forbidden exceptions
                } catch (IOException e) {
-                       logger.warn(MessageFormat.format(
-                                       "Failed to retrieve SETTINGS from federated gitblit ({0} @ {1})",
-                                       registration.name, registration.url), e);
+                       logger.warn("Failed to retrieve SETTINGS from federated gitblit ({} @ {})",     registration.name, registration.url, e);
                }
 
                try {
@@ -463,9 +447,7 @@ public abstract class FederationPullService implements Runnable {
                } catch (ForbiddenException e) {
                        // ignore forbidden exceptions
                } catch (IOException e) {
-                       logger.warn(MessageFormat.format(
-                                       "Failed to retrieve SCRIPTS from federated gitblit ({0} @ {1})",
-                                       registration.name, registration.url), e);
+                       logger.warn("Failed to retrieve SCRIPTS from federated gitblit ({} @ {})", registration.name, registration.url, e);
                }
        }
 
@@ -487,6 +469,6 @@ public abstract class FederationPullService implements Runnable {
                        federationName = addr.getHostName();
                }
                FederationUtils.acknowledgeStatus(addr.getHostAddress(), registration);
-               logger.info(MessageFormat.format("Pull status sent to {0}", registration.url));
+               logger.info("Pull status sent to {}", registration.url);
        }
 }
\ No newline at end of file
index b98560fd95e16ef0bf9274f9dc7df4fd2efd317e..dc095503e567ca51140b2e328711e42631212f88 100644 (file)
@@ -15,7 +15,6 @@
  */\r
 package com.gitblit.service;\r
 \r
-import java.text.MessageFormat;\r
 import java.util.Calendar;\r
 import java.util.Date;\r
 import java.util.Map;\r
@@ -143,7 +142,7 @@ public class GarbageCollectorService implements Runnable {
                                break;\r
                        }\r
                        if (isCollectingGarbage(repositoryName)) {\r
-                               logger.warn(MessageFormat.format("Already collecting garbage from {0}?!?", repositoryName));\r
+                               logger.warn("Already collecting garbage from {}?!?", repositoryName);\r
                                continue;\r
                        }\r
                        boolean garbageCollected = false;\r
@@ -153,12 +152,12 @@ public class GarbageCollectorService implements Runnable {
                                model = repositoryManager.getRepositoryModel(repositoryName);\r
                                repository = repositoryManager.getRepository(repositoryName);\r
                                if (repository == null) {\r
-                                       logger.warn(MessageFormat.format("GCExecutor is missing repository {0}?!?", repositoryName));\r
+                                       logger.warn("GCExecutor is missing repository {}?!?", repositoryName);\r
                                        continue;\r
                                }\r
 \r
                                if (!repositoryManager.isIdle(repository)) {\r
-                                       logger.debug(MessageFormat.format("GCExecutor is skipping {0} because it is not idle", repositoryName));\r
+                                       logger.debug("GCExecutor is skipping {} because it is not idle", repositoryName);\r
                                        continue;\r
                                }\r
 \r
@@ -166,11 +165,11 @@ public class GarbageCollectorService implements Runnable {
                                // disabling *all* access to this repository from Gitblit.\r
                                // Think of this as a clutch in a manual transmission vehicle.\r
                                if (!setGCStatus(repositoryName, GCStatus.COLLECTING)) {\r
-                                       logger.warn(MessageFormat.format("Can not acquire GC lock for {0}, skipping", repositoryName));\r
+                                       logger.warn("Can not acquire GC lock for {}, skipping", repositoryName);\r
                                        continue;\r
                                }\r
 \r
-                               logger.debug(MessageFormat.format("GCExecutor locked idle repository {0}", repositoryName));\r
+                               logger.debug("GCExecutor locked idle repository {}", repositoryName);\r
 \r
                                Git git = new Git(repository);\r
                                GarbageCollectCommand gc = git.gc();\r
@@ -196,7 +195,7 @@ public class GarbageCollectorService implements Runnable {
                                boolean hasGarbage = sizeOfLooseObjects > 0;\r
                                if (hasGarbage && (hasEnoughGarbage || shouldCollectGarbage)) {\r
                                        long looseKB = sizeOfLooseObjects/1024L;\r
-                                       logger.info(MessageFormat.format("Collecting {1} KB of loose objects from {0}", repositoryName, looseKB));\r
+                                       logger.info("Collecting {} KB of loose objects from {}", looseKB, repositoryName );\r
 \r
                                        // do the deed\r
                                        gc.call();\r
@@ -204,7 +203,7 @@ public class GarbageCollectorService implements Runnable {
                                        garbageCollected = true;\r
                                }\r
                        } catch (Exception e) {\r
-                               logger.error("Error collecting garbage in " + repositoryName, e);\r
+                               logger.error("Error collecting garbage in {}", repositoryName, e);\r
                        } finally {\r
                                // cleanup\r
                                if (repository != null) {\r
@@ -219,7 +218,7 @@ public class GarbageCollectorService implements Runnable {
 \r
                                // reset the GC lock\r
                                releaseLock(repositoryName);\r
-                               logger.debug(MessageFormat.format("GCExecutor released GC lock for {0}", repositoryName));\r
+                               logger.debug("GCExecutor released GC lock for {}", repositoryName);\r
                        }\r
                }\r
 \r
index 906a0b5e60f7d34ac942a0a8c6bbbb1906dcc6aa..2d9fc9f9d5e4bdac1e5ec1397d0cf3e1a68009d3 100644 (file)
@@ -172,7 +172,7 @@ public class LuceneService implements Runnable {
                                Repository repository = repositoryManager.getRepository(model.name);\r
                                if (repository == null) {\r
                                        if (repositoryManager.isCollectingGarbage(model.name)) {\r
-                                               logger.info(MessageFormat.format("Skipping Lucene index of {0}, busy garbage collecting", repositoryName));\r
+                                               logger.info("Skipping Lucene index of {}, busy garbage collecting", repositoryName);\r
                                        }\r
                                        continue;\r
                                }\r
@@ -200,9 +200,8 @@ public class LuceneService implements Runnable {
 \r
                                if (result.success) {\r
                                        if (result.commitCount > 0) {\r
-                                               String msg = "Built {0} Lucene index from {1} commits and {2} files across {3} branches in {4} secs";\r
-                                               logger.info(MessageFormat.format(msg, model.name, result.commitCount,\r
-                                                               result.blobCount, result.branchCount, result.duration()));\r
+                                               logger.info("Built {} Lucene index from {} commits and {} files across {} branches in {} secs",\r
+                                                                       model.name, result.commitCount, result.blobCount, result.branchCount, result.duration());\r
                                        }\r
                                } else {\r
                                        String msg = "Could not build {0} Lucene index!";\r
@@ -213,17 +212,15 @@ public class LuceneService implements Runnable {
                                IndexResult result = updateIndex(model, repository);\r
                                if (result.success) {\r
                                        if (result.commitCount > 0) {\r
-                                               String msg = "Updated {0} Lucene index with {1} commits and {2} files across {3} branches in {4} secs";\r
-                                               logger.info(MessageFormat.format(msg, model.name, result.commitCount,\r
-                                                               result.blobCount, result.branchCount, result.duration()));\r
+                                               logger.info("Updated {} Lucene index with {} commits and {} files across {} branches in {} secs",\r
+                                                                       model.name, result.commitCount, result.blobCount, result.branchCount, result.duration());\r
                                        }\r
                                } else {\r
-                                       String msg = "Could not update {0} Lucene index!";\r
-                                       logger.error(MessageFormat.format(msg, model.name));\r
+                                       logger.error("Could not update {} Lucene index!", model.name);\r
                                }\r
                        }\r
                } catch (Throwable t) {\r
-                       logger.error(MessageFormat.format("Lucene indexing failure for {0}", model.name), t);\r
+                       logger.error("Lucene indexing failure for {}", model.name, t);\r
                }\r
        }\r
 \r
@@ -239,7 +236,7 @@ public class LuceneService implements Runnable {
                                searcher.getIndexReader().close();\r
                        }\r
                } catch (Exception e) {\r
-                       logger.error("Failed to close index searcher for " + repositoryName, e);\r
+                       logger.error("Failed to close index searcher for {}", repositoryName, e);\r
                }\r
 \r
                try {\r
@@ -248,7 +245,7 @@ public class LuceneService implements Runnable {
                                writer.close();\r
                        }\r
                } catch (Exception e) {\r
-                       logger.error("Failed to close index writer for " + repositoryName, e);\r
+                       logger.error("Failed to close index writer for {}", repositoryName, e);\r
                }\r
        }\r
 \r
@@ -262,7 +259,7 @@ public class LuceneService implements Runnable {
                        try {\r
                                writers.get(writer).close();\r
                        } catch (Throwable t) {\r
-                               logger.error("Failed to close Lucene writer for " + writer, t);\r
+                               logger.error("Failed to close Lucene writer for {}", writer, t);\r
                        }\r
                }\r
                writers.clear();\r
@@ -272,7 +269,7 @@ public class LuceneService implements Runnable {
                        try {\r
                                searchers.get(searcher).getIndexReader().close();\r
                        } catch (Throwable t) {\r
-                               logger.error("Failed to close Lucene searcher for " + searcher, t);\r
+                               logger.error("Failed to close Lucene searcher for {}", searcher, t);\r
                        }\r
                }\r
                searchers.clear();\r
@@ -594,7 +591,7 @@ public class LuceneService implements Runnable {
                        resetIndexSearcher(model.name);\r
                        result.success();\r
                } catch (Exception e) {\r
-                       logger.error("Exception while reindexing " + model.name, e);\r
+                       logger.error("Exception while reindexing {}", model.name, e);\r
                }\r
                return result;\r
        }\r
@@ -673,7 +670,7 @@ public class LuceneService implements Runnable {
                        result.commitCount++;\r
                        result.success = index(repositoryName, doc);\r
                } catch (Exception e) {\r
-                       logger.error(MessageFormat.format("Exception while indexing commit {0} in {1}", commit.getId().getName(), repositoryName), e);\r
+                       logger.error("Exception while indexing commit {} in {}", commit.getId().getName(), repositoryName, e);\r
                }\r
                return result;\r
        }\r
@@ -701,10 +698,10 @@ public class LuceneService implements Runnable {
                writer.commit();\r
                int numDocsAfter = writer.numDocs();\r
                if (numDocsBefore == numDocsAfter) {\r
-                       logger.debug(MessageFormat.format("no records found to delete {0}", query.toString()));\r
+                       logger.debug("no records found to delete {}", query.toString());\r
                        return false;\r
                } else {\r
-                       logger.debug(MessageFormat.format("deleted {0} records with {1}", numDocsBefore - numDocsAfter, query.toString()));\r
+                       logger.debug("deleted {} records with {}", numDocsBefore - numDocsAfter, query.toString());\r
                        return true;\r
                }\r
        }\r
@@ -833,7 +830,7 @@ public class LuceneService implements Runnable {
                        }\r
                        result.success = true;\r
                } catch (Throwable t) {\r
-                       logger.error(MessageFormat.format("Exception while updating {0} Lucene index", model.name), t);\r
+                       logger.error("Exception while updating {} Lucene index", model.name, t);\r
                }\r
                return result;\r
        }\r
@@ -876,7 +873,7 @@ public class LuceneService implements Runnable {
                        resetIndexSearcher(repositoryName);\r
                        return true;\r
                } catch (Exception e) {\r
-                       logger.error(MessageFormat.format("Exception while incrementally updating {0} Lucene index", repositoryName), e);\r
+                       logger.error("Exception while incrementally updating {} Lucene index", repositoryName, e);\r
                }\r
                return false;\r
        }\r
@@ -1049,7 +1046,7 @@ public class LuceneService implements Runnable {
                                results.add(result);\r
                        }\r
                } catch (Exception e) {\r
-                       logger.error(MessageFormat.format("Exception while searching for {0}", text), e);\r
+                       logger.error("Exception while searching for {}", text, e);\r
                }\r
                return new ArrayList<SearchResult>(results);\r
        }\r
index eb247fc0c383a940286e5f2ab3cac1a9b3b01e2c..08d5401313e706a01f50046a2cd0ecdbb95ed4cb 100644 (file)
@@ -119,7 +119,7 @@ public class MirrorService implements Runnable {
 \r
                                repository = repositoryManager.getRepository(repositoryName);\r
                                if (repository == null) {\r
-                                       logger.warn(MessageFormat.format("MirrorExecutor is missing repository {0}?!?", repositoryName));\r
+                                       logger.warn("MirrorExecutor is missing repository {}?!?", repositoryName);\r
                                        continue;\r
                                }\r
 \r
@@ -204,7 +204,7 @@ public class MirrorService implements Runnable {
                                        }\r
                                }\r
                        } catch (Exception e) {\r
-                               logger.error("Error updating mirror " + repositoryName, e);\r
+                               logger.error("Error updating mirror {}", repositoryName, e);\r
                        } finally {\r
                                // cleanup\r
                                if (repository != null) {\r
index 8430c546b3a9ee274d8950f3cf2f637b9694ad11..3add609d3a35ac73fb1cdba68c66ffa25140ed0e 100644 (file)
@@ -16,7 +16,6 @@
 package com.gitblit.tickets;
 
 import java.io.IOException;
-import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -169,20 +168,19 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                                                if (!ids.contains(ticketId)) {
                                                        ids.add(ticketId);
                                                        TicketModel ticket = getTicket(repository, ticketId);
-                                                       log.info(MessageFormat.format("indexing ticket #{0,number,0}: {1}",
-                                                                       ticketId, ticket.title));
+                                                       log.info("indexing ticket #{}: {}",     ticketId, ticket.title);
                                                        indexer.index(ticket);
                                                }
                                        }
                                        long end = System.nanoTime();
-                                       log.info("incremental indexing of {0} ticket(s) completed in {1} msecs",
+                                       log.info("incremental indexing of {} ticket(s) completed in {} msecs",
                                                        ids.size(), TimeUnit.NANOSECONDS.toMillis(end - start));
                                } finally {
                                        db.close();
                                }
                                break;
                        default:
-                               log.warn("Unexpected receive type {} in BranchTicketService.onRefsChanged" + cmd.getType());
+                               log.warn("Unexpected receive type {} in BranchTicketService.onRefsChanged", cmd.getType());
                                break;
                        }
                } catch (Exception e) {
@@ -216,10 +214,10 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                                Result res = cmd.rename();
                                switch (res) {
                                case RENAMED:
-                                       log.info(db.getDirectory() + " " + cmd.getRefLogMessage());
+                                       log.info("{} {}", db.getDirectory(), cmd.getRefLogMessage());
                                        return getTicketsBranch(db);
                                default:
-                                       log.error("failed to rename " + oldRef.getName() + " => " + BRANCH + " (" + res.name() + ")");
+                                       log.error("failed to rename {} => {} ({})", oldRef.getName(), BRANCH, res.name());
                                }
                        } catch (IOException e) {
                                log.error("failed to rename tickets branch", e);
@@ -288,7 +286,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                                return JGitUtils.getStringContent(db, tree, file, Constants.ENCODING);
                        }
                } catch (IOException e) {
-                       log.error("failed to read " + file, e);
+                       log.error("failed to read {}", file, e);
                } finally {
                        if (rw != null) {
                                rw.close();
@@ -506,8 +504,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                                                }
                                        }
                                } catch (Exception e) {
-                                       log.error("failed to deserialize {}/{}\n{}",
-                                                       new Object [] { repository, path.path, e.getMessage()});
+                                       log.error("failed to deserialize {}/{}\n{}", repository, path.path, e.getMessage());
                                        log.error(null, e);
                                }
                        }
@@ -701,8 +698,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                                success = commitIndex(db, index, deletedBy, "- " + ticket.number);
 
                        } catch (Throwable t) {
-                               log.error(MessageFormat.format("Failed to delete ticket {0,number,0} from {1}",
-                                               ticket.number, db.getDirectory()), t);
+                               log.error("Failed to delete ticket {} from {}", ticket.number, db.getDirectory(), t);
                        } finally {
                                // release the treewalk
                                if (treeWalk != null) {
@@ -733,8 +729,7 @@ public class BranchTicketService extends ITicketService implements RefsChangedLi
                        success = commitIndex(db, index, change.author, "#" + ticketId);
 
                } catch (Throwable t) {
-                       log.error(MessageFormat.format("Failed to commit ticket {0,number,0} to {1}",
-                                       ticketId, db.getDirectory()), t);
+                       log.error("Failed to commit ticket {} to {}", ticketId, db.getDirectory(), t);
                } finally {
                        db.close();
                }
index 05670468a404a57f83022708eda2b784b501816a..5b45547da61344783e4db5e8cb6549d365e97ef5 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.tickets;
 
 import java.io.File;
 import java.io.IOException;
-import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -274,8 +273,7 @@ public class FileTicketService extends ITicketService {
                                                }
                                        }
                                } catch (Exception e) {
-                                       log.error("failed to deserialize {}/{}\n{}",
-                                                       new Object [] { repository, journal, e.getMessage()});
+                                       log.error("failed to deserialize {}/{}\n{}", repository, journal, e.getMessage());
                                        log.error(null, e);
                                }
                        }
@@ -481,8 +479,7 @@ public class FileTicketService extends ITicketService {
                        FileUtils.writeContent(file, journal);
                        success = true;
                } catch (Throwable t) {
-                       log.error(MessageFormat.format("Failed to commit ticket {0,number,0} to {1}",
-                                       ticketId, db.getDirectory()), t);
+                       log.error("Failed to commit ticket {} to {}", ticketId, db.getDirectory(), t);
                } finally {
                        db.close();
                }
index 3252a603f27f91b19dba8f30eef42eb91996e351..6ab87aeb9ea9f1bd14f3402dc6309d802367d79c 100644 (file)
@@ -363,7 +363,7 @@ public abstract class ITicketService implements IManager {
                        }
                        labelsCache.put(key,  Collections.unmodifiableList(list));
                } catch (Exception e) {
-                       log.error("invalid tickets settings for " + repository, e);
+                       log.error("invalid tickets settings for {}", repository, e);
                } finally {
                        db.close();
                }
@@ -408,7 +408,7 @@ public abstract class ITicketService implements IManager {
                        config.setString(LABEL, label, COLOR, lb.color);
                        config.save();
                } catch (IOException e) {
-                       log.error("failed to create label " + label + " in " + repository, e);
+                       log.error("failed to create label {} in {}", label, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -436,7 +436,7 @@ public abstract class ITicketService implements IManager {
 
                        return true;
                } catch (IOException e) {
-                       log.error("failed to update label " + label + " in " + repository, e);
+                       log.error("failed to update label {} in {}", label, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -477,7 +477,7 @@ public abstract class ITicketService implements IManager {
 
                        return true;
                } catch (IOException e) {
-                       log.error("failed to rename label " + oldName + " in " + repository, e);
+                       log.error("failed to rename label {} in {}", oldName, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -508,7 +508,7 @@ public abstract class ITicketService implements IManager {
 
                        return true;
                } catch (IOException e) {
-                       log.error("failed to delete label " + label + " in " + repository, e);
+                       log.error("failed to delete label {} in {}", label, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -543,15 +543,14 @@ public abstract class ITicketService implements IManager {
                                        try {
                                                milestone.due = new SimpleDateFormat(DUE_DATE_PATTERN).parse(due);
                                        } catch (ParseException e) {
-                                               log.error("failed to parse {} milestone {} due date \"{}\"",
-                                                               new Object [] { repository, name, due });
+                                               log.error("failed to parse {} milestone {} due date \"{}\"", repository, name, due, e);
                                        }
                                }
                                list.add(milestone);
                        }
                        milestonesCache.put(key, Collections.unmodifiableList(list));
                } catch (Exception e) {
-                       log.error("invalid tickets settings for " + repository, e);
+                       log.error("invalid tickets settings for {}", repository, e);
                } finally {
                        db.close();
                }
@@ -617,7 +616,7 @@ public abstract class ITicketService implements IManager {
 
                        milestonesCache.remove(repository.name);
                } catch (IOException e) {
-                       log.error("failed to create milestone " + milestone + " in " + repository, e);
+                       log.error("failed to create milestone {} in {}", milestone, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -651,7 +650,7 @@ public abstract class ITicketService implements IManager {
                        milestonesCache.remove(repository.name);
                        return true;
                } catch (IOException e) {
-                       log.error("failed to update milestone " + milestone + " in " + repository, e);
+                       log.error("failed to update milestone {} in {}", milestone, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -724,7 +723,7 @@ public abstract class ITicketService implements IManager {
 
                        return true;
                } catch (IOException e) {
-                       log.error("failed to rename milestone " + oldName + " in " + repository, e);
+                       log.error("failed to rename milestone {} in {}", oldName, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -788,7 +787,7 @@ public abstract class ITicketService implements IManager {
                        }
                        return true;
                } catch (IOException e) {
-                       log.error("failed to delete milestone " + milestone + " in " + repository, e);
+                       log.error("failed to delete milestone {} in {}", milestone, repository, e);
                } finally {
                        if (db != null) {
                                db.close();
@@ -1219,8 +1218,7 @@ public abstract class ITicketService implements IManager {
                TicketModel ticket = getTicket(repository, ticketId);
                boolean success = deleteTicketImpl(repository, ticket, deletedBy);
                if (success) {
-                       log.info(MessageFormat.format("Deleted {0} ticket #{1,number,0}: {2}",
-                                       repository.name, ticketId, ticket.title));
+                       log.info("Deleted {} ticket #{}: {}", repository.name, ticketId, ticket.title);
                        ticketsCache.invalidate(new TicketKey(repository, ticketId));
                        indexer.delete(ticket);
                        return true;
index 4e632317f3d9d1d88b056a23ecc26eaad869a627..ae4fffef771dd81ab00f3ade3a885fb20684bb7a 100644 (file)
@@ -181,7 +181,7 @@ public class RedisTicketService extends ITicketService {
                        Boolean exists = jedis.exists(key(repository, KeyType.journal, ticketId));
                        return exists != null && exists;
                } catch (JedisException e) {
-                       log.error("failed to check hasTicket from Redis @ " + getUrl(), e);
+                       log.error("failed to check hasTicket from Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -205,7 +205,7 @@ public class RedisTicketService extends ITicketService {
                                ids.add(ticketId);
                        }
                } catch (JedisException e) {
-                       log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
+                       log.error("failed to assign new ticket id in Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -241,7 +241,7 @@ public class RedisTicketService extends ITicketService {
                        long ticketNumber = jedis.incr(key);
                        return ticketNumber;
                } catch (JedisException e) {
-                       log.error("failed to assign new ticket id in Redis @ " + getUrl(), e);
+                       log.error("failed to assign new ticket id in Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -300,7 +300,7 @@ public class RedisTicketService extends ITicketService {
                        // sort the tickets by creation
                        Collections.sort(list);
                } catch (JedisException e) {
-                       log.error("failed to retrieve tickets from Redis @ " + getUrl(), e);
+                       log.error("failed to retrieve tickets from Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -338,7 +338,7 @@ public class RedisTicketService extends ITicketService {
                        log.debug("rebuilt ticket {} from Redis @ {}", ticketId, getUrl());
                        return ticket;
                } catch (JedisException e) {
-                       log.error("failed to retrieve ticket from Redis @ " + getUrl(), e);
+                       log.error("failed to retrieve ticket from Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -371,7 +371,7 @@ public class RedisTicketService extends ITicketService {
                        }
                        return changes;
                } catch (JedisException e) {
-                       log.error("failed to retrieve journal from Redis @ " + getUrl(), e);
+                       log.error("failed to retrieve journal from Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -454,9 +454,9 @@ public class RedisTicketService extends ITicketService {
                        t.exec();
 
                        success = true;
-                       log.debug("deleted ticket {} from Redis @ {}", "" + ticket.number, getUrl());
+                       log.debug("deleted ticket {} from Redis @ {}", ticket.number, getUrl());
                } catch (JedisException e) {
-                       log.error("failed to delete ticket from Redis @ " + getUrl(), e);
+                       log.error("failed to delete ticket from Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -497,10 +497,10 @@ public class RedisTicketService extends ITicketService {
                        t.rpush(key(repository, KeyType.journal, ticketId), journal);
                        t.exec();
 
-                       log.debug("updated ticket {} in Redis @ {}", "" + ticketId, getUrl());
+                       log.debug("updated ticket {} in Redis @ {}", ticketId, getUrl());
                        return true;
                } catch (JedisException e) {
-                       log.error("failed to update ticket cache in Redis @ " + getUrl(), e);
+                       log.error("failed to update ticket cache in Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -532,7 +532,7 @@ public class RedisTicketService extends ITicketService {
                        }
                        success = true;
                } catch (JedisException e) {
-                       log.error("failed to delete all tickets in Redis @ " + getUrl(), e);
+                       log.error("failed to delete all tickets in Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
@@ -561,7 +561,7 @@ public class RedisTicketService extends ITicketService {
                        t.exec();
                        success = true;
                } catch (JedisException e) {
-                       log.error("failed to rename tickets in Redis @ " + getUrl(), e);
+                       log.error("failed to rename tickets in Redis @ {}", getUrl(), e);
                        pool.returnBrokenResource(jedis);
                        jedis = null;
                } finally {
index 7c1644872c721f30817e41e9775faaf9d16029d6..09da11774b34960cbcbafb340c541c6e5e49804a 100644 (file)
@@ -17,7 +17,6 @@ package com.gitblit.tickets;
 
 import java.io.File;
 import java.io.IOException;
-import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -214,10 +213,10 @@ public class TicketIndexer {
                        closeSearcher();
                        int numDocsAfter = writer.numDocs();
                        if (numDocsBefore == numDocsAfter) {
-                               log.debug(MessageFormat.format("no records found to delete in {0}", repository));
+                               log.debug("no records found to delete in {}", repository);
                                return false;
                        } else {
-                               log.debug(MessageFormat.format("deleted {0} records in {1}", numDocsBefore - numDocsAfter, repository));
+                               log.debug("deleted {} records in {}", numDocsBefore - numDocsAfter, repository);
                                return true;
                        }
                } catch (Exception e) {
@@ -287,7 +286,7 @@ public class TicketIndexer {
                        IndexWriter writer = getWriter();
                        return delete(ticket.repository, ticket.number, writer);
                } catch (Exception e) {
-                       log.error("Failed to delete ticket " + ticket.number, e);
+                       log.error("Failed to delete ticket {}", ticket.number, e);
                }
                return false;
        }
@@ -311,10 +310,10 @@ public class TicketIndexer {
                closeSearcher();
                int numDocsAfter = writer.numDocs();
                if (numDocsBefore == numDocsAfter) {
-                       log.debug(MessageFormat.format("no records found to delete in {0}", repository));
+                       log.debug("no records found to delete in {}", repository);
                        return false;
                } else {
-                       log.debug(MessageFormat.format("deleted {0} records in {1}", numDocsBefore - numDocsAfter, repository));
+                       log.debug("deleted {} records in {}", numDocsBefore - numDocsAfter, repository);
                        return true;
                }
        }
@@ -383,7 +382,7 @@ public class TicketIndexer {
                                results.add(result);
                        }
                } catch (Exception e) {
-                       log.error(MessageFormat.format("Exception while searching for {0}", text), e);
+                       log.error("Exception while searching for {}", text, e);
                }
                return new ArrayList<QueryResult>(results);
        }
@@ -435,7 +434,7 @@ public class TicketIndexer {
                                results.add(result);
                        }
                } catch (Exception e) {
-                       log.error(MessageFormat.format("Exception while searching for {0}", queryText), e);
+                       log.error("Exception while searching for {}", queryText, e);
                }
                return new ArrayList<QueryResult>(results);
        }
index b913db2572a6182b7b063411e500dc1b27571f8f..f284e7be3d8f9bcd50a673fea378101fd13c287b 100644 (file)
@@ -34,10 +34,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.apache.commons.io.IOUtils;
-import org.apache.log4j.Logger;
 import org.eclipse.jgit.diff.DiffEntry.ChangeType;
 import org.eclipse.jgit.lib.Repository;
 import org.eclipse.jgit.revwalk.RevCommit;
+import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.gitblit.Constants;
@@ -96,6 +96,8 @@ public class TicketNotifier {
        private final String addPattern = "<span style=\"color:darkgreen;\">+{0}</span>";
        private final String delPattern = "<span style=\"color:darkred;\">-{0}</span>";
 
+       private final Logger log = LoggerFactory.getLogger(getClass());
+
        public TicketNotifier(
                        IRuntimeManager runtimeManager,
                        INotificationManager notificationManager,
@@ -152,7 +154,7 @@ public class TicketNotifier {
 
                        return mailing;
                } catch (Exception e) {
-                       Logger.getLogger(getClass()).error("failed to queue mailing for #" + ticket.number, e);
+                       log.error("failed to queue mailing for #{}", ticket.number, e);
                }
                return null;
        }
@@ -203,7 +205,7 @@ public class TicketNotifier {
                                diffstat = DiffUtils.getDiffStat(repo, base, patchset.tip);
                                commits = JGitUtils.getRevLog(repo, base, patchset.tip);
                        } catch (Exception e) {
-                               Logger.getLogger(getClass()).error("failed to get changed paths", e);
+                               log.error("failed to get changed paths", e);
                        } finally {
                                if (repo != null) {
                                        repo.close();
@@ -552,9 +554,7 @@ public class TicketNotifier {
                                        if (user.canView(repository)) {
                                                toAddresses.add(user.emailAddress);
                                        } else {
-                                               LoggerFactory.getLogger(getClass()).warn(
-                                                               MessageFormat.format("ticket {0}-{1,number,0}: {2} can not receive notification",
-                                                                               repository.name, ticket.number, user.username));
+                                               log.warn("ticket {}-{}: {} can not receive notification", repository.name, ticket.number, user.username);
                                        }
                                }
                        }
@@ -594,9 +594,7 @@ public class TicketNotifier {
                                        if (user.canView(repository)) {
                                                ccAddresses.add(user.emailAddress);
                                        } else {
-                                               LoggerFactory.getLogger(getClass()).warn(
-                                                               MessageFormat.format("ticket {0}-{1,number,0}: {2} can not receive notification",
-                                                                               repository.name, ticket.number, user.username));
+                                               log.warn("ticket {}-{}: {} can not receive notification", repository.name, ticket.number, user.username);
                                        }
                                }
                        }