]> source.dussan.org Git - archiva.git/commitdiff
Utilize parameterized logging and remove toString() calls
authorDaniel Trebbien <dtrebbien@gmail.com>
Sun, 30 Jul 2017 20:26:05 +0000 (13:26 -0700)
committerDaniel Trebbien <dtrebbien@gmail.com>
Sun, 30 Jul 2017 20:26:05 +0000 (13:26 -0700)
As suggested in the SLF4J FAQ:
https://www.slf4j.org/faq.html#logging_performance
.. parameterized logging can improve the efficiency of logger calls when
logging at the specified level is disabled.

In addition, per the FAQ: https://www.slf4j.org/faq.html#paramException
since SLF4J 1.6.0 it is possible to use parameterized logging and also
log an exception/throwable.

toString() is called automatically:
https://www.slf4j.org/faq.html#string_contents

These changes were suggested by SLF4J Helper for NetBeans IDE:
http://plugins.netbeans.org/plugin/72557/

23 files changed:
archiva-modules/archiva-base/archiva-configuration/src/main/java/org/apache/archiva/configuration/DefaultArchivaConfiguration.java
archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/consumers/core/repository/AbstractRepositoryPurgeTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTest.java
archiva-modules/archiva-base/archiva-filelock/src/test/java/org/apache/archiva/common/filelock/DefaultFileLockManagerTimeoutTest.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/AbstractRepositoryAdminTest.java
archiva-modules/archiva-base/archiva-repository-scanner/src/main/java/org/apache/archiva/repository/scanner/functors/ConsumerProcessFileClosure.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultCommonServices.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultPluginsServices.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/runtime/ldap/ArchivaLdapConnectionFactory.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaUserManagerAuthenticator.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/SecuritySynchronization.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/util/MimeTypes.java
archiva-modules/plugins/audit/src/main/java/org/apache/archiva/audit/DefaultAuditManager.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/DefaultCassandraArchivaManager.java
archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/metadata-store-jcr/src/main/java/org/apache/archiva/metadata/repository/jcr/JcrMetadataRepository.java
archiva-modules/plugins/repository-statistics/src/main/java/org/apache/archiva/metadata/repository/stats/DefaultRepositoryStatisticsManager.java

index 45477877f87d704228117f22da15f576ec8f432d..f8aea6e7a6c8cf0957eacfb6b12a1474c1df84b4 100644 (file)
@@ -703,7 +703,7 @@ public class DefaultArchivaConfiguration
         }
         catch ( IOException e )
         {
-            log.error( "Unable to create " + filetype + " file: " + e.getMessage(), e );
+            log.error( "Unable to create {} file: {}", filetype, e.getMessage(), e );
             return false;
         }
     }
index 9412ac73c3df6da28c342de240d4f39fb010eaf8..1a997eea7ffe259342611bdaa3bf82b5fb45dfb8 100644 (file)
@@ -144,7 +144,7 @@ public abstract class AbstractRepositoryPurgeTest
         if ( path.contains( " " ) )
         {
             LoggerFactory.getLogger( AbstractRepositoryPurgeTest.class.getName() ).error(
-                "You are building and testing with a path: \n " + path + " containing space. Consider relocating." );
+                "You are building and testing with a path: \n {} containing space. Consider relocating.", path );
             return path.replaceAll( " ", "&amp;20" );
         }
         return path;
index aa999bd6fa8b14807c172772ed76a243d048b9bb..66f067f34da111f8ee972973d73a1240774f1311 100644 (file)
@@ -219,7 +219,7 @@ public class NexusIndexerConsumer
         }
         catch ( TaskQueueException e )
         {
-            log.error( "Error queueing task: " + task + ": " + e.getMessage(), e );
+            log.error( "Error queueing task: {}: {}", task, e.getMessage(), e );
         }
     }
 
index af189ba49814593a19536c0cf337bf051a939c38..adcdbc7a8ea016ca9e10b1b1a623297118ee9cff 100644 (file)
@@ -112,7 +112,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread1 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -132,7 +132,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread2 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -156,7 +156,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread3 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -177,7 +177,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread4 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -198,7 +198,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread5 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -221,7 +221,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread6 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -242,7 +242,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread7 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -265,7 +265,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread8 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -286,7 +286,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread9 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
@@ -308,7 +308,7 @@ public class DefaultFileLockManagerTest {
                 logger.info("thread10 ok");
                 success.incrementAndGet();
             } catch (Throwable e) {
-                logger.error("Error occured " + e.getMessage());
+                logger.error("Error occured {}", e.getMessage());
                 e.printStackTrace();
                 throw e;
             }
index 666efee1881dcc518375d539c5d8c87b26f83cae..514dfde0201eb2ce557ccfd5e765a61863c85154 100644 (file)
@@ -76,14 +76,14 @@ public class DefaultFileLockManagerTimeoutTest
                 try {
                     Files.copy(largeJar.toPath(), lock.getFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
                 } catch (IOException e) {
-                    logger.warn("Copy failed "+e.getMessage());
+                    logger.warn("Copy failed {}", e.getMessage());
                     // On windows a FileSystemException is thrown
                     // We ignore this
                 }
 
                 lock = fileLockManager.writeFileLock(file);
             } catch (FileSystemException ex) {
-                logger.error("Exception from filesystem "+ex.getMessage());
+                logger.error("Exception from filesystem {}", ex.getMessage());
                 ex.printStackTrace();
                 throw ex;
             }
index 5d60874159c05441c780fd7ab77a07a5f6fb837e..1397c7eb5c87b4536cf4cf684b89361db62218df 100644 (file)
@@ -428,10 +428,9 @@ public class DefaultRepositoryProxyConnectors
                     "Transfer error from repository {} for resource {}, continuing to next repository. Error message: {}",
                     targetRepository.getRepository().getId(), path, e.getMessage() );
                 log.debug( MarkerFactory.getDetachedMarker( "transfer.error" ),
-                           "Transfer error from repository \"" + targetRepository.getRepository().getId()
-                               + "\" for resource " + path + ", continuing to next repository. Error message: {}",
-                           e.getMessage(), e
-                );
+                           "Transfer error from repository \"{}"
+                               + "\" for resource {}, continuing to next repository. Error message: {}",
+                           targetRepository.getRepository().getId(), path, e.getMessage(), e );
             }
             catch ( RepositoryAdminException e )
             {
@@ -830,8 +829,8 @@ public class DefaultRepositoryProxyConnectors
         }
         catch ( TaskQueueException e )
         {
-            log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
-                           + "']." );
+            log.error( "Unable to queue repository task to execute consumers on resource file ['{}"
+                           + "'].", localFile.getName() );
         }
     }
 
index 96d217d5906c43a3e3ecf03a938f6df0ee01d1d3..bfaa9c6916604bf649fa6989f3c8e98256dcde4d 100644 (file)
@@ -89,8 +89,8 @@ public abstract class AbstractRepositoryAdminTest
         if ( path.contains( SPACE ) )
         {
             LoggerFactory.getLogger( AbstractRepositoryAdminTest.class.getName() ).error(
-                "You are building and testing  with {appserver.base}: \n " + path
-                    + " containing space. Consider relocating." );
+                "You are building and testing  with {appserver.base}: \n {}"
+                    + " containing space. Consider relocating.", path );
         }
         return path.replaceAll( SPACE, "&amp;20" );
     }
index ca44dd9ba5ba9d0f302c52a6e2042979084fc0d9..85375bc001d7ed2009160773820bc3ac73586578 100644 (file)
@@ -77,8 +77,8 @@ public class ConsumerProcessFileClosure
                 /* Intentionally Catch all exceptions.
                  * So that the discoverer processing can continue.
                  */
-                log.error( "Consumer [" + id + "] had an error when processing file ["
-                    + basefile.getAbsolutePath() + "]: " + e.getMessage(), e );
+                log.error( "Consumer [{}] had an error when processing file ["
+                    + "{}]: {}", id, basefile.getAbsolutePath(), e.getMessage(), e );
             }
         }
     }
index 71fb584605ed38b730f2894d8d9bcf84b00a605e..1509bef12c5cf591436c41d3e3b9f5d142b9f969 100644 (file)
@@ -135,7 +135,7 @@ public class ArchivaIndexingTaskExecutor
                 }
                 catch ( RepositoryAdminException e )
                 {
-                    log.error( "Error occurred while creating context: " + e.getMessage() );
+                    log.error( "Error occurred while creating context: {}", e.getMessage() );
                     throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(), e );
                 }
             }
@@ -227,7 +227,7 @@ public class ArchivaIndexingTaskExecutor
             }
             catch ( IOException e )
             {
-                log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage(),
+                log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage(),
                            e );
                 throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                                   e );
@@ -261,7 +261,7 @@ public class ArchivaIndexingTaskExecutor
         }
         catch ( IOException e )
         {
-            log.error( "Error occurred while executing indexing task '" + indexingTask + "': " + e.getMessage() );
+            log.error( "Error occurred while executing indexing task '{}': {}", indexingTask, e.getMessage() );
             throw new TaskExecutionException( "Error occurred while executing indexing task '" + indexingTask + "'",
                                               e );
         }
index b7cb60d348e5684f989e129368fb37930402bde2..180cee7478820b1224c122cf00f205336fed735e 100644 (file)
@@ -83,7 +83,7 @@ public class DefaultCommonServices
         }
         catch ( IOException e )
         {
-            log.warn( "skip error loading properties {}", resourceName.toString() );
+            log.warn( "skip error loading properties {}", resourceName );
         }
 
         return fromProperties( properties );
index 208400c832021de19bad5644d7030627ad0310cf..d6f190819e5c85201579c8e96b01e87f267e8716 100644 (file)
@@ -72,7 +72,7 @@ public class DefaultPluginsServices
         {
             sb.append( repoType ).append( "|" );
         }
-        log.debug( "getAdminPlugins: {}", sb.toString() );
+        log.debug( "getAdminPlugins: {}", sb );
         if ( sb.length() > 1 )
         {
             adminPlugins = sb.substring( 0, sb.length() - 1 );
index e0660c269fa1c15e02cae00d2b7aea5a21d670fb..a5f6844cabe1d88a454483523238a3a7fe54ce67 100644 (file)
@@ -352,7 +352,7 @@ public class DefaultRepositoriesService
         }
         catch ( AuthorizationException e )
         {
-            log.error( "error reading permission: " + e.getMessage(), e );
+            log.error( "error reading permission: {}", e.getMessage(), e );
             throw new ArchivaRestServiceException( e.getMessage(), e );
         }
 
@@ -370,7 +370,7 @@ public class DefaultRepositoriesService
         }
         catch ( AuthorizationException e )
         {
-            log.error( "error reading permission: " + e.getMessage(), e );
+            log.error( "error reading permission: {}", e.getMessage(), e );
             throw new ArchivaRestServiceException( e.getMessage(), e );
         }
 
@@ -394,7 +394,7 @@ public class DefaultRepositoriesService
 
             if ( StringUtils.isEmpty( artifactSourcePath ) )
             {
-                log.error( "cannot find artifact " + artifactTransferRequest.toString() );
+                log.error( "cannot find artifact {}", artifactTransferRequest );
                 throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
                                                        null );
             }
@@ -403,7 +403,7 @@ public class DefaultRepositoriesService
 
             if ( !artifactFile.exists() )
             {
-                log.error( "cannot find artifact " + artifactTransferRequest.toString() );
+                log.error( "cannot find artifact {}", artifactTransferRequest );
                 throw new ArchivaRestServiceException( "cannot find artifact " + artifactTransferRequest.toString(),
                                                        null );
             }
@@ -487,17 +487,17 @@ public class DefaultRepositoriesService
         }
         catch ( RepositoryException e )
         {
-            log.error( "RepositoryException: " + e.getMessage(), e );
+            log.error( "RepositoryException: {}", e.getMessage(), e );
             throw new ArchivaRestServiceException( e.getMessage(), e );
         }
         catch ( RepositoryAdminException e )
         {
-            log.error( "RepositoryAdminException: " + e.getMessage(), e );
+            log.error( "RepositoryAdminException: {}", e.getMessage(), e );
             throw new ArchivaRestServiceException( e.getMessage(), e );
         }
         catch ( IOException e )
         {
-            log.error( "IOException: " + e.getMessage(), e );
+            log.error( "IOException: {}", e.getMessage(), e );
             throw new ArchivaRestServiceException( e.getMessage(), e );
         }
         return true;
@@ -517,8 +517,8 @@ public class DefaultRepositoriesService
         }
         catch ( TaskQueueException e )
         {
-            log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
-                           + "']." );
+            log.error( "Unable to queue repository task to execute consumers on resource file ['{}"
+                           + "'].", localFile.getName() );
         }
     }
 
index e4d6676d62db363183fdcc572e81cce89462fa27..af0164d9e623387c07a19bffe87e062f1bf05e47 100644 (file)
@@ -569,8 +569,8 @@ public class DefaultFileUploadService
         }
         catch ( TaskQueueException e )
         {
-            log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
-                           + "']." );
+            log.error( "Unable to queue repository task to execute consumers on resource file ['{}"
+                           + "'].", localFile.getName() );
         }
     }
 
index 45945f1046bdb2edd764c2fb62ab51c3e14a9708..55dad7b3952671feb77a0b7d49fd43a1927b42b7 100644 (file)
@@ -73,7 +73,7 @@ public class ArchivaLdapConnectionFactory
         }
         catch ( InvalidNameException e )
         {
-            log.error("Error during initialization of LdapConnectionFactory "+e.getMessage(),e);
+            log.error( "Error during initialization of LdapConnectionFactory {}", e.getMessage(), e );
             // throw new RuntimeException( "Error while initializing connection factory.", e );
         }
         catch ( RepositoryAdminException e )
index b1cbc9cf8e3496630669154b2f96b8a8f689fe61..0acc266bf9089fa4cf503de47023de3572a0d4c1 100644 (file)
@@ -89,7 +89,7 @@ public class ArchivaUserManagerAuthenticator
         }
         catch ( RepositoryAdminException e )
         {
-            log.error("Error during repository initialization "+e.getMessage(),e);
+            log.error( "Error during repository initialization {}", e.getMessage(), e );
             // throw new AuthenticationException( e.getMessage(), e );
         }
     }
index 0e28b51af6b3cde07e72d441e17dfada5631d86a..4ddbbd9c006fa0fd2192475a1d7a5521d72d43cd 100644 (file)
@@ -152,7 +152,7 @@ public class SecuritySynchronization
         catch ( RoleManagerException e )
         {
             // Log error.
-            log.error( "Unable to create roles for configured repositories: " + e.getMessage(), e );
+            log.error( "Unable to create roles for configured repositories: {}", e.getMessage(), e );
         }
     }
 
index 074d13bdae21c17689dec0458b1e5a19a74b8ed4..6a14e2130daa2ca3668259d48ceebc7d5fd707ea 100644 (file)
@@ -723,8 +723,8 @@ public class ArchivaDavResource
         }
         catch ( TaskQueueException e )
         {
-            log.error( "Unable to queue repository task to execute consumers on resource file ['" + localFile.getName()
-                           + "']." );
+            log.error( "Unable to queue repository task to execute consumers on resource file ['{}"
+                           + "'].", localFile.getName() );
         }
     }
 }
index 092c4b10080c2496e8d85136463004fb39a1acd7..e42d6344c62da77e4ca3da619aa0769f9f2f89ac 100644 (file)
@@ -100,7 +100,7 @@ public class MimeTypes
         }
         catch ( IOException e )
         {
-            log.error( "Unable to load mime map " + resourceName + " : " + e.getMessage(), e );
+            log.error( "Unable to load mime map {} : {}", resourceName, e.getMessage(), e );
         }
     }
 
@@ -146,7 +146,7 @@ public class MimeTypes
         }
         catch ( IOException e )
         {
-            log.error( "Unable to read mime types from input stream : " + e.getMessage(), e );
+            log.error( "Unable to read mime types from input stream : {}", e.getMessage(), e );
         }
     }
 
index 44086185cb6c28e3a045ae8af635f083196e2d0a..510dc8191749f5c63609a01e5c31301b0493fc3c 100644 (file)
@@ -134,7 +134,7 @@ public class DefaultAuditManager
                 }
                 catch ( ParseException e )
                 {
-                    log.error( "Invalid audit event found in the metadata repository: " + e.getMessage() );
+                    log.error( "Invalid audit event found in the metadata repository: {}", e.getMessage() );
                     // continue and ignore this one
                 }
             }
index 44b02997d39717295854fc3077a10d8cc9f9f29d..d0185d9fc6f6a772f6cdb1077cf87c7aca51c2b2 100644 (file)
@@ -458,7 +458,7 @@ public class DefaultCassandraArchivaManager
         { // ensure keyspace exists, here if the keyspace doesn't exist we suppose nothing exist
             if ( cluster.describeKeyspace( keyspaceName ) == null )
             {
-                logger.info( "Creating Archiva Cassandra '" + keyspaceName + "' keyspace." );
+                logger.info( "Creating Archiva Cassandra '{}' keyspace.", keyspaceName );
                 cluster.addKeyspace( HFactory.createKeyspaceDefinition( keyspaceName, //
                                                                         ThriftKsDef.DEF_STRATEGY_CLASS, //
                                                                         replicationFactor, //
index 2cea31c3673e6875f2cab486dc0182dcd3208e4d..7a3af1aaf45da3bea80833a6b429e41e38448cf3 100644 (file)
@@ -570,7 +570,7 @@ public class FileMetadataRepository
                                 MetadataFacetFactory factory = metadataFacetFactories.get( facetId );
                                 if ( factory == null )
                                 {
-                                    log.error( "Attempted to load unknown artifact metadata facet: " + facetId );
+                                    log.error( "Attempted to load unknown artifact metadata facet: {}", facetId );
                                 }
                                 else
                                 {
index 2b76db4aff83c1c6c932c6d9d47e5f319b02e67a..f8393b888f50ddb40b01a1b135f0e10a460fec7b 100644 (file)
@@ -1353,7 +1353,7 @@ public class JcrMetadataRepository
             getJcrSession().save();
         } catch ( InvalidItemStateException e ) {
             // olamy this might happen when deleting a repo while is under scanning
-            log.warn( "skip InvalidItemStateException:" + e.getMessage(), e );
+            log.warn( "skip InvalidItemStateException:{}", e.getMessage(), e );
         }
         catch ( RepositoryException e )
         {
@@ -1493,7 +1493,7 @@ public class JcrMetadataRepository
                 MetadataFacetFactory factory = metadataFacetFactories.get( name );
                 if ( factory == null )
                 {
-                    log.error( "Attempted to load unknown project version metadata facet: " + name );
+                    log.error( "Attempted to load unknown project version metadata facet: {}", name );
                 }
                 else
                 {
index f7c4dcc847421593ecc45062ef292938932896ca..9611bbb67f5f8b9d7be369b52207944fd8afa012 100644 (file)
@@ -156,7 +156,7 @@ public class DefaultRepositoryStatisticsManager
             }
             catch ( ParseException e )
             {
-                log.error( "Invalid scan result found in the metadata repository: " + e.getMessage() );
+                log.error( "Invalid scan result found in the metadata repository: {}", e.getMessage() );
                 // continue and ignore this one
             }
         }