[CST-6265] Fixed message formatting

fix:
	- message formatting for logInfo was done twice
feat:
	- message inside logWarn was not formatted when using handler
This commit is contained in:
Vincenzo Mecca
2022-09-08 18:45:11 +02:00
parent 3884007521
commit 33e6339900
2 changed files with 20 additions and 10 deletions

View File

@@ -189,8 +189,7 @@ public class Curation extends DSpaceRunnable<CurationScriptConfiguration> {
* @throws FileNotFoundException If file of command line variable -r reporter is not found
*/
private Curator initCurator() throws FileNotFoundException {
Curator curator = new Curator();
curator.setLogHandler(handler);
Curator curator = new Curator(handler);
OutputStream reporterStream;
if (null == this.reporter) {
reporterStream = new NullOutputStream();

View File

@@ -9,6 +9,7 @@ package org.dspace.curate;
import java.io.IOException;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -93,6 +94,16 @@ public class Curator {
protected HandleService handleService;
protected DSpaceRunnableHandler handler;
/**
* constructor that uses an handler for logging
*
* @param handler {@code DSpaceRunnableHandler} used to logs infos
*/
public Curator(DSpaceRunnableHandler handler) {
this();
this.handler = handler;
}
/**
* No-arg constructor
*/
@@ -607,11 +618,11 @@ public class Curator {
return mb.toString();
}
protected void logInfo(String id) {
protected void logInfo(String message) {
if (handler == null) {
log.info(logMessage(id));
log.info(message);
} else {
handler.logInfo(logMessage(id));
handler.logInfo(message);
}
}
@@ -629,11 +640,11 @@ public class Curator {
log.warn(message);
}
} else {
handler.logWarning(message);
if (object != null) {
handler.logWarning(MessageFormat.format(message, object));
} else {
handler.logWarning(message);
}
}
}
public void setLogHandler(DSpaceRunnableHandler handler) {
this.handler = handler;
}
}