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.
This commit is contained in:
Marten Deinum
2020-12-03 15:58:53 +01:00
committed by Mahmoud Ben Hassine
parent abc937dec2
commit ff3c7c1e58
30 changed files with 175 additions and 102 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}

View File

@@ -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<T> implements ItemReader<List<T>> {
}
// 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;
}

View File

@@ -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<Order> {
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> {
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);
}
}
}

View File

@@ -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<Person> {
@Override
public void write(List<? extends Person> data) {
log.debug("Processing: " + data);
if (log.isDebugEnabled()) {
log.debug("Processing: " + data);
}
}
}

View File

@@ -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());

View File

@@ -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");

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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<Object> people) throws Exception {
for(Object person : people) {
LOG.info("Writing person: " + person);
if (LOG.isInfoEnabled()) {
LOG.info("Writing person: " + person);
}
}
}
}

View File

@@ -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);

View File

@@ -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<String, Object> 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);