From b7d144c10d43e18b06f7921d751f97e21ab4a9a7 Mon Sep 17 00:00:00 2001 From: Marten Deinum Date: Thu, 3 Dec 2020 15:58:53 +0100 Subject: [PATCH] Added isXXXEnabled for logging statements Guarded the logging statements which do concatenation of strings or calling toString on objects. When a log level isn't enabled this still would produce garbage that would need to be collected. Guarded all logging up to info, warn and error can be assumed to be enabled on a production system. --- .../JobFactoryRegistrationListener.java | 10 ++++-- .../batch/core/job/AbstractJob.java | 8 +++-- .../batch/core/job/SimpleStepHandler.java | 18 ++++++---- .../jsr/configuration/xml/BatchParser.java | 6 ++-- .../xml/JsrBeanDefinitionDocumentReader.java | 4 +-- .../batch/core/jsr/job/JsrStepHandler.java | 10 ++++-- .../step/builder/JsrPartitionStepBuilder.java | 8 +++-- .../JobRegistryBackgroundJobRunner.java | 19 ++++++---- .../launch/support/SimpleJobLauncher.java | 26 ++++++++------ .../launch/support/SimpleJobOperator.java | 36 +++++++++++-------- .../support/JobRepositoryFactoryBean.java | 8 +++-- .../batch/core/step/AbstractStep.java | 7 ++-- .../step/builder/PartitionStepBuilder.java | 8 +++-- .../core/step/builder/SimpleStepBuilder.java | 6 ++-- .../item/file/transform/DefaultFieldSet.java | 4 +-- .../chunk/ChunkMessageChannelItemWriter.java | 6 ++-- .../sample/common/InfiniteLoopWriter.java | 6 ++-- .../batch/sample/common/LogAdvice.java | 8 +++-- .../sample/common/StagingItemReader.java | 7 ++-- .../domain/multiline/AggregateItemReader.java | 6 ++-- .../order/internal/OrderItemReader.java | 11 +++--- .../domain/person/internal/PersonWriter.java | 6 ++-- .../domain/trade/internal/JdbcTradeDao.java | 6 ++-- .../sample/jsr352/JsrSampleBatchlet.java | 7 ++-- .../sample/jsr352/JsrSampleItemProcessor.java | 7 ++-- .../sample/jsr352/JsrSampleItemReader.java | 7 ++-- .../sample/jsr352/JsrSampleItemWriter.java | 6 ++-- .../batch/sample/jsr352/JsrSampleTasklet.java | 6 ++-- .../sample/quartz/JobLauncherDetails.java | 6 ++-- .../batch/test/DataSourceInitializer.java | 4 +-- 30 files changed, 175 insertions(+), 102 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListener.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListener.java index db246f5df..9df2959a8 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListener.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/JobFactoryRegistrationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,7 +54,9 @@ public class JobFactoryRegistrationListener { * @throws Exception if there is a problem */ public void bind(JobFactory jobFactory, Map params) throws Exception { - logger.info("Binding JobFactory: " + jobFactory.getJobName()); + if (logger.isInfoEnabled()) { + logger.info("Binding JobFactory: " + jobFactory.getJobName()); + } jobRegistry.register(jobFactory); } @@ -66,7 +68,9 @@ public class JobFactoryRegistrationListener { * @throws Exception if there is a problem */ public void unbind(JobFactory jobFactory, Map params) throws Exception { - logger.info("Unbinding JobFactory: " + jobFactory.getJobName()); + if (logger.isInfoEnabled()) { + logger.info("Unbinding JobFactory: " + jobFactory.getJobName()); + } jobRegistry.unregister(jobFactory.getJobName()); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java index 1115e4e98..006102f01 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/AbstractJob.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -337,8 +337,10 @@ InitializingBean { } } catch (JobInterruptedException e) { - logger.info("Encountered interruption executing job: " - + e.getMessage()); + if (logger.isInfoEnabled()) { + logger.info("Encountered interruption executing job: " + + e.getMessage()); + } if (logger.isDebugEnabled()) { logger.debug("Full exception", e); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleStepHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleStepHandler.java index bab83122a..27b784714 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleStepHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/job/SimpleStepHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -116,9 +116,11 @@ public class SimpleStepHandler implements StepHandler, InitializingBean { if (stepExecutionPartOfExistingJobExecution(execution, lastStepExecution)) { // If the last execution of this step was in the same job, it's // probably intentional so we want to run it again... - logger.info(String.format("Duplicate step [%s] detected in execution of job=[%s]. " - + "If either step fails, both will be executed again on restart.", step.getName(), jobInstance - .getJobName())); + if (logger.isInfoEnabled()) { + logger.info(String.format("Duplicate step [%s] detected in execution of job=[%s]. " + + "If either step fails, both will be executed again on restart.", step.getName(), jobInstance + .getJobName())); + } lastStepExecution = null; } StepExecution currentStepExecution = lastStepExecution; @@ -143,7 +145,9 @@ public class SimpleStepHandler implements StepHandler, InitializingBean { jobRepository.add(currentStepExecution); - logger.info("Executing step: [" + step.getName() + "]"); + if (logger.isInfoEnabled()) { + logger.info("Executing step: [" + step.getName() + "]"); + } try { step.execute(currentStepExecution); currentStepExecution.getExecutionContext().put("batch.executed", true); @@ -215,7 +219,9 @@ public class SimpleStepHandler implements StepHandler, InitializingBean { || stepStatus == BatchStatus.ABANDONED) { // step is complete, false should be returned, indicating that the // step should not be started - logger.info("Step already complete or not restartable, so no action to execute: " + lastStepExecution); + if (logger.isInfoEnabled()) { + logger.info("Step already complete or not restartable, so no action to execute: " + lastStepExecution); + } return false; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/BatchParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/BatchParser.java index e09e79b04..dce8a0d94 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/BatchParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/BatchParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +71,9 @@ public class BatchParser extends AbstractBeanDefinitionParser { if(!registry.containsBeanDefinition(beanName)) { registry.registerBeanDefinition(beanName, beanDefinition); } else { - logger.info("Ignoring batch.xml bean definition for " + beanName + " because another bean of the same name has been registered"); + if (logger.isInfoEnabled()) { + logger.info("Ignoring batch.xml bean definition for " + beanName + " because another bean of the same name has been registered"); + } } } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java index e11ea43b9..2e86e4dfc 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/configuration/xml/JsrBeanDefinitionDocumentReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -200,7 +200,7 @@ public class JsrBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocume String resolvedProperty = properties.getProperty(extractedProperty, NULL); - if (NULL.equals(resolvedProperty)) { + if (NULL.equals(resolvedProperty) && LOG.isInfoEnabled()) { LOG.info(propertyType + " with key of: " + extractedProperty + " could not be resolved. Possible configuration error?"); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/job/JsrStepHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/job/JsrStepHandler.java index 4a2e242ed..36092e81e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/job/JsrStepHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/job/JsrStepHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,7 +93,9 @@ public class JsrStepHandler extends SimpleStepHandler { if(CollectionUtils.isEmpty(jobExecution.getStepExecutions()) && lastJobExecution.getStatus() == BatchStatus.STOPPED && StringUtils.hasText(restartStep)) { if(!restartStep.equals(step.getName()) && !jobExecution.getExecutionContext().containsKey("batch.startedStep")) { - logger.info("Job was stopped and should restart at step " + restartStep + ". The current step is " + step.getName()); + if (logger.isInfoEnabled()) { + logger.info("Job was stopped and should restart at step " + restartStep + ". The current step is " + step.getName()); + } return false; } else { // Indicates the starting point for execution evaluation per JSR-352 @@ -113,7 +115,9 @@ public class JsrStepHandler extends SimpleStepHandler { || stepStatus == BatchStatus.ABANDONED) { // step is complete, false should be returned, indicating that the // step should not be started - logger.info("Step already complete or not restartable, so no action to execute: " + lastStepExecution); + if (logger.isInfoEnabled()) { + logger.info("Step already complete or not restartable, so no action to execute: " + lastStepExecution); + } return false; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/builder/JsrPartitionStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/builder/JsrPartitionStepBuilder.java index 48a76e80e..12a9a410e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/builder/JsrPartitionStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/jsr/step/builder/JsrPartitionStepBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -94,8 +94,10 @@ public class JsrPartitionStepBuilder extends PartitionStepBuilder { name = getStep().getName(); } catch (Exception e) { - logger.info("Ignored exception from step asking for name and allowStartIfComplete flag. " - + "Using default from enclosing PartitionStep (" + name + "," + allowStartIfComplete + ")."); + if (logger.isInfoEnabled()) { + logger.info("Ignored exception from step asking for name and allowStartIfComplete flag. " + + "Using default from enclosing PartitionStep (" + name + "," + allowStartIfComplete + ")."); + } } } SimpleStepExecutionSplitter splitter = new SimpleStepExecutionSplitter(); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JobRegistryBackgroundJobRunner.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JobRegistryBackgroundJobRunner.java index 692512d0a..d4eeedb6b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JobRegistryBackgroundJobRunner.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/JobRegistryBackgroundJobRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2013 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -131,7 +131,9 @@ public class JobRegistryBackgroundJobRunner { for (int j = 0; j < resources.length; j++) { Resource path = resources[j]; - logger.info("Registering Job definitions from " + Arrays.toString(resources)); + if (logger.isInfoEnabled()) { + logger.info("Registering Job definitions from " + Arrays.toString(resources)); + } GenericApplicationContextFactory factory = new GenericApplicationContextFactory(path); factory.setApplicationContext(parentContext); @@ -199,8 +201,9 @@ public class JobRegistryBackgroundJobRunner { final JobRegistryBackgroundJobRunner launcher = new JobRegistryBackgroundJobRunner(args[0]); errors.clear(); - logger.info("Starting job registry in parent context from XML at: [" + args[0] + "]"); - + if (logger.isInfoEnabled()) { + logger.info("Starting job registry in parent context from XML at: [" + args[0] + "]"); + } new Thread(new Runnable() { @Override public void run() { @@ -221,7 +224,9 @@ public class JobRegistryBackgroundJobRunner { synchronized (errors) { if (!errors.isEmpty()) { - logger.info(errors.size() + " errors detected on startup of parent context. Rethrowing."); + if (logger.isInfoEnabled()) { + logger.info(errors.size() + " errors detected on startup of parent context. Rethrowing."); + } throw errors.get(0); } } @@ -231,7 +236,9 @@ public class JobRegistryBackgroundJobRunner { final String[] paths = new String[args.length - 1]; System.arraycopy(args, 1, paths, 0, paths.length); - logger.info("Parent context started. Registering jobs from paths: " + Arrays.asList(paths)); + if (logger.isInfoEnabled()) { + logger.info("Parent context started. Registering jobs from paths: " + Arrays.asList(paths)); + } launcher.register(paths); if (System.getProperty(EMBEDDED) != null) { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java index fdd14fff8..ae6bbac74 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobLauncher.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -142,18 +142,24 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean { @Override public void run() { try { - logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters - + "]"); + if (logger.isInfoEnabled()) { + logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters + + "]"); + } job.execute(jobExecution); - Duration jobExecutionDuration = BatchMetrics.calculateDuration(jobExecution.getStartTime(), jobExecution.getEndTime()); - logger.info("Job: [" + job + "] completed with the following parameters: [" + jobParameters - + "] and the following status: [" + jobExecution.getStatus() + "]" - + (jobExecutionDuration == null ? "" : " in " + BatchMetrics.formatDuration(jobExecutionDuration))); + if (logger.isInfoEnabled()) { + Duration jobExecutionDuration = BatchMetrics.calculateDuration(jobExecution.getStartTime(), jobExecution.getEndTime()); + logger.info("Job: [" + job + "] completed with the following parameters: [" + jobParameters + + "] and the following status: [" + jobExecution.getStatus() + "]" + + (jobExecutionDuration == null ? "" : " in " + BatchMetrics.formatDuration(jobExecutionDuration))); + } } catch (Throwable t) { - logger.info("Job: [" + job - + "] failed unexpectedly and fatally with the following parameters: [" + jobParameters - + "]", t); + if (logger.isInfoEnabled()) { + logger.info("Job: [" + job + + "] failed unexpectedly and fatally with the following parameters: [" + jobParameters + + "]", t); + } rethrow(t); } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java index 5fc0d3582..c7aba90dd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/SimpleJobOperator.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -267,15 +267,18 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { @Override public Long restart(long executionId) throws JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException, JobRestartException, JobParametersInvalidException { - logger.info("Checking status of job execution with id=" + executionId); - + if (logger.isInfoEnabled()) { + logger.info("Checking status of job execution with id=" + executionId); + } JobExecution jobExecution = findExecutionById(executionId); String jobName = jobExecution.getJobInstance().getJobName(); Job job = jobRegistry.getJob(jobName); JobParameters parameters = jobExecution.getJobParameters(); - logger.info(String.format("Attempting to resume job with name=%s and parameters=%s", jobName, parameters)); + if (logger.isInfoEnabled()) { + logger.info(String.format("Attempting to resume job with name=%s and parameters=%s", jobName, parameters)); + } try { return jobLauncher.run(job, parameters).getId(); } @@ -295,8 +298,9 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { */ @Override public Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException { - - logger.info("Checking status of job with name=" + jobName); + if (logger.isInfoEnabled()) { + logger.info("Checking status of job with name=" + jobName); + } JobParameters jobParameters = jobParametersConverter.getJobParameters(PropertiesConverter .stringToProperties(parameters)); @@ -308,8 +312,9 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { } Job job = jobRegistry.getJob(jobName); - - logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); + if (logger.isInfoEnabled()) { + logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); + } try { return jobLauncher.run(job, jobParameters).getId(); } @@ -336,15 +341,17 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { @Override public Long startNextInstance(String jobName) throws NoSuchJobException, UnexpectedJobExecutionException, JobParametersInvalidException { - - logger.info("Locating parameters for next instance of job with name=" + jobName); + if (logger.isInfoEnabled()) { + logger.info("Locating parameters for next instance of job with name=" + jobName); + } Job job = jobRegistry.getJob(jobName); JobParameters parameters = new JobParametersBuilder(jobExplorer) .getNextJobParameters(job) .toJobParameters(); - - logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); + if (logger.isInfoEnabled()) { + logger.info(String.format("Attempting to launch job with name=%s and parameters=%s", jobName, parameters)); + } try { return jobLauncher.run(job, parameters).getId(); } @@ -424,8 +431,9 @@ public class SimpleJobOperator implements JobOperator, InitializingBean { throw new JobExecutionAlreadyRunningException( "JobExecution is running or complete and therefore cannot be aborted"); } - - logger.info("Aborting job execution: " + jobExecution); + if (logger.isInfoEnabled()) { + logger.info("Aborting job execution: " + jobExecution); + } jobExecution.upgradeStatus(BatchStatus.ABANDONED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java index 3fa06d23d..763e7c819 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -181,7 +181,9 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i if (databaseType == null) { databaseType = DatabaseType.fromMetaData(dataSource).name(); - logger.info("No database type set, using meta data indicating: " + databaseType); + if (logger.isInfoEnabled()) { + logger.info("No database type set, using meta data indicating: " + databaseType); + } } if (lobHandler == null && databaseType.equalsIgnoreCase(DatabaseType.ORACLE.toString())) { @@ -194,7 +196,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean i serializer = defaultSerializer; } - Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), "'" + databaseType + Assert.isTrue(incrementerFactory.isSupportedIncrementerType(databaseType), () -> "'" + databaseType + "' is an unsupported database type. The supported database types are " + StringUtils.arrayToCommaDelimitedString(incrementerFactory.getSupportedIncrementerTypes())); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java index 08dd2f993..4df145cc6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -269,8 +269,9 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw stepExecution.setEndTime(new Date()); stepExecution.setExitStatus(exitStatus); Duration stepExecutionDuration = BatchMetrics.calculateDuration(stepExecution.getStartTime(), stepExecution.getEndTime()); - logger.info("Step: [" + stepExecution.getStepName() + "] executed in " + BatchMetrics.formatDuration(stepExecutionDuration)); - + if (logger.isInfoEnabled()) { + logger.info("Step: [" + stepExecution.getStepName() + "] executed in " + BatchMetrics.formatDuration(stepExecutionDuration)); + } try { getJobRepository().update(stepExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/PartitionStepBuilder.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/PartitionStepBuilder.java index fcf88cc62..733f2f66c 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/PartitionStepBuilder.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/builder/PartitionStepBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -189,8 +189,10 @@ public class PartitionStepBuilder extends StepBuilderHelper extends AbstractTaskletStepBuilder extends StepExecutionListenerSuppo int count = 0; int maxCount = maxWaitTimeouts; Throwable failure = null; - logger.info("Waiting for " + localState.getExpecting() + " results"); + if (logger.isInfoEnabled()) { + logger.info("Waiting for " + localState.getExpecting() + " results"); + } while (localState.getExpecting() > 0 && count++ < maxCount) { try { getNextResult(); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java index a58d0b1bd..b34a1a613 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/InfiniteLoopWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,6 +61,8 @@ public class InfiniteLoopWriter extends StepExecutionListenerSupport implements } stepExecution.setWriteCount(++count); - LOG.info("Executing infinite loop, at count=" + count); + if (LOG.isInfoEnabled()) { + LOG.info("Executing infinite loop, at count=" + count); + } } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/LogAdvice.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/LogAdvice.java index bf26cc646..e1444134a 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/LogAdvice.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/LogAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,9 @@ import org.apache.commons.logging.LogFactory; public class LogAdvice { private static Log log = LogFactory.getLog(LogAdvice.class); - public void doStronglyTypedLogging(Object item){ - log.info("Processed: " + item); + public void doStronglyTypedLogging(Object item) { + if (log.isInfoEnabled()) { + log.info("Processed: " + item); + } } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java index 140d5964c..bd8c0ed4f 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/common/StagingItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,8 +110,9 @@ InitializingBean, DisposableBean { id = keys.next(); } } - logger.debug("Retrieved key from list: " + id); - + if (logger.isDebugEnabled()) { + logger.debug("Retrieved key from list: " + id); + } if (id == null) { return null; } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemReader.java index a81d6ce24..ec949f789 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -90,7 +90,9 @@ public class AggregateItemReader implements ItemReader> { } // add a simple record to the current collection - LOG.debug("Mapping: " + value); + if (LOG.isDebugEnabled()) { + LOG.debug("Mapping: " + value); + } holder.addRecord(value.getItem()); return true; } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderItemReader.java index 3a4c110bc..b358434ed 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/order/internal/OrderItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,8 +68,9 @@ public class OrderItemReader implements ItemReader { process(fieldSetReader.read()); } - log.info("Mapped: " + order); - + if (log.isInfoEnabled()) { + log.info("Mapped: " + order); + } Order result = order; order = null; @@ -144,7 +145,9 @@ public class OrderItemReader implements ItemReader { order.getLineItems().add(itemMapper.mapFieldSet(fieldSet)); } else { - log.debug("Could not map LINE_ID=" + lineId); + if (log.isDebugEnabled()) { + log.debug("Could not map LINE_ID=" + lineId); + } } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/person/internal/PersonWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/person/internal/PersonWriter.java index bd10d6613..2400d7846 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/person/internal/PersonWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/person/internal/PersonWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,8 @@ public class PersonWriter implements ItemWriter { @Override public void write(List data) { - log.debug("Processing: " + data); + if (log.isDebugEnabled()) { + log.debug("Processing: " + data); + } } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java index 5f947c712..d38f2247c 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/trade/internal/JdbcTradeDao.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,9 @@ public class JdbcTradeDao implements TradeDao { @Override public void writeTrade(Trade trade) { Long id = incrementer.nextLongValue(); - log.debug("Processing: " + trade); + if (log.isDebugEnabled()) { + log.debug("Processing: " + trade); + } jdbcTemplate.update(INSERT_TRADE_RECORD, id, trade.getIsin(), trade.getQuantity(), trade.getPrice(), trade.getCustomer()); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleBatchlet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleBatchlet.java index 150fc272b..7cf728506 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleBatchlet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleBatchlet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,8 +39,9 @@ public class JsrSampleBatchlet extends AbstractBatchlet { @Override public String process() throws Exception { - LOG.info("Calling remote service at: " + remoteServiceURL); - + if (LOG.isInfoEnabled()) { + LOG.info("Calling remote service at: " + remoteServiceURL); + } Thread.sleep(2000); LOG.info("Remote service call complete"); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemProcessor.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemProcessor.java index ba46665d2..e172a4cc7 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemProcessor.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,8 +35,9 @@ public class JsrSampleItemProcessor implements ItemProcessor { public Object processItem(Object o) throws Exception { String person = (String) o; - LOG.info("Transforming person: " + person + " to uppercase"); - + if (LOG.isInfoEnabled()) { + LOG.info("Transforming person: " + person + " to uppercase"); + } return person.toUpperCase(); } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java index f72ce2c8f..d2d1fba72 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,9 @@ public class JsrSampleItemReader extends AbstractItemReader { if(people.iterator().hasNext()) { person = people.iterator().next(); people.remove(person); - - LOG.info("Read person: " + person); + if (LOG.isInfoEnabled()) { + LOG.info("Read person: " + person); + } } return person; diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemWriter.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemWriter.java index 362368907..787ee97d2 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemWriter.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleItemWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,9 @@ public class JsrSampleItemWriter extends AbstractItemWriter { @Override public void writeItems(List people) throws Exception { for(Object person : people) { - LOG.info("Writing person: " + person); + if (LOG.isInfoEnabled()) { + LOG.info("Writing person: " + person); + } } } } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleTasklet.java index 79d17cf8e..1b11a215e 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/jsr352/JsrSampleTasklet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,9 @@ public class JsrSampleTasklet implements Tasklet { @Nullable @Override public RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception { - LOG.info("Calling remote service at: " + remoteServiceURL); + if (LOG.isInfoEnabled()) { + LOG.info("Calling remote service at: " + remoteServiceURL); + } Thread.sleep(2000); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/quartz/JobLauncherDetails.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/quartz/JobLauncherDetails.java index a38a313ab..81cb32ac0 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/quartz/JobLauncherDetails.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/quartz/JobLauncherDetails.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,9 @@ public class JobLauncherDetails extends QuartzJobBean { protected void executeInternal(JobExecutionContext context) { Map jobDataMap = context.getMergedJobDataMap(); String jobName = (String) jobDataMap.get(JOB_NAME); - log.info("Quartz trigger firing with Spring Batch jobName="+jobName); + if (log.isInfoEnabled()) { + log.info("Quartz trigger firing with Spring Batch jobName=" + jobName); + } JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap); try { jobLauncher.run(jobLocator.getJob(jobName), jobParameters); diff --git a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java index 1fa840dce..d6958983c 100755 --- a/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java +++ b/spring-batch-test/src/main/java/org/springframework/batch/test/DataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -144,7 +144,7 @@ public class DataSourceInitializer implements InitializingBean, DisposableBean { jdbcTemplate.execute(trimmedScript); } catch (DataAccessException e) { - if (this.ignoreFailedDrop && trimmedScript.toLowerCase().startsWith("drop")) { + if (this.ignoreFailedDrop && trimmedScript.toLowerCase().startsWith("drop") && logger.isDebugEnabled()) { logger.debug("DROP script failed (ignoring): " + trimmedScript); } else {