From f1405eaa2240dac6b4459055a15eed69571adbbb Mon Sep 17 00:00:00 2001 From: TobiasNx Date: Wed, 18 Sep 2024 11:00:03 +0200 Subject: [PATCH] Add log function #319 --- .../org/metafacture/metafix/FixMethod.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java index 4ae2ac32..8eb9f4f0 100644 --- a/metafix/src/main/java/org/metafacture/metafix/FixMethod.java +++ b/metafix/src/main/java/org/metafacture/metafix/FixMethod.java @@ -43,6 +43,9 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public enum FixMethod implements FixFunction { // checkstyle-disable-line ClassDataAbstractionCoupling|ClassFanOutComplexity // SCRIPT-LEVEL METHODS: @@ -62,6 +65,23 @@ public void apply(final Metafix metafix, final Record record, final List metafix.getRecordTransformer(includePath).transform(record, options); } }, + log { + @Override + public void apply(final Metafix metafix, final Record record, final List params, final Map options) { + final String logMessage = params.get(0); + final String logLevel = options.get("level"); // does not support Catmandu lop level option FATAL + + if (logLevel.equals("WARN")) { + LOG.warn(logMessage); + } + else if (logLevel.equals("ERROR")) { + LOG.error(logMessage); + } + else { + LOG.info(logMessage); + } + } + }, nothing { @Override public void apply(final Metafix metafix, final Record record, final List params, final Map options) { @@ -691,4 +711,6 @@ public void apply(final Metafix metafix, final Record record, final List private static final Random RANDOM = new Random(); + private static final Logger LOG = LoggerFactory.getLogger(FixMethod.class); + }