I am using a Spring batch job to load a file into database. The file contains sensitive customer data. On any parsing error, Spring batch logs the exception along with the file line content.
Parsing error at line: 1 in resource=[file [/path/file.txt]], input=[sensitive data]
I would like to avoid the possibility of those with access to copy paste the log in their communications with parties not authorized for this particular piece of data. Hence I disabled the Spring batch log using application.properties setting
logging.level.org.springframework.batch: OFF
However I still need to log the file name, line number and the cause of error. Thought of something like below in StepExecutionListener::afterStep, but this may not be foolproof/future-proof.
stepExecution.getFailureExceptions()
.forEach(e -> log.error(e.getMessage().replaceAll("[, ]*input=\\[.*?]", "") + " - " + e.getCause()));
What other approaches can I try? Is there a setting to instruct Spring batch to mask/exclude the file content in the exception message?