From 5d4723b9e86e02ab39c6849c430d0e7172e85fad Mon Sep 17 00:00:00 2001 From: Kai Brassel <mail@khbrassel.de> Date: Thu, 10 Jun 2021 09:55:52 +0200 Subject: [PATCH] Try Eclipse logging --- .../cityunits/model/NullableQuantity.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java index 5e26301..3c8ad9d 100644 --- a/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java +++ b/de.hftstuttgart.cityunits.model/src/de/hftstuttgart/cityunits/model/NullableQuantity.java @@ -10,6 +10,12 @@ import java.util.logging.Logger; import javax.measure.Quantity; import javax.measure.Unit; +import org.eclipse.core.runtime.ILog; +import org.eclipse.core.runtime.Platform; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; +import org.eclipse.core.runtime.Status; + import tech.units.indriya.format.SimpleQuantityFormat; import tech.units.indriya.quantity.Quantities; @@ -21,7 +27,8 @@ import tech.units.indriya.quantity.Quantities; * of the quantity is always defined. */ public class NullableQuantity { - static Logger LOGGER = Logger.getLogger("de.hftstuttgart.cityunits"); + private static final Bundle BUNDLE = FrameworkUtil.getBundle(NullableQuantity.class); + private static final ILog LOGGER = Platform.getLog(BUNDLE); static { // TODO Implement specific QuantityFormat to enable custom number format? @@ -36,19 +43,22 @@ public class NullableQuantity { public static NullableQuantity create(String str) { NullableQuantity newNullableQuantity = null; try { - LOGGER.log(Level.INFO, "Create Quantity from " + str); + LOGGER.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), "Create Quantity from " + str)); NumberFormat.getInstance().parse(str); newNullableQuantity = new NullableQuantity(str); } catch (final ParseException ex) { // no number value present: create NullQuantity just with unit try { NullableQuantity dummy = new NullableQuantity("1 " + str); //$NON-NLS-1$ - LOGGER.log(Level.INFO, "Create Quantity just with unit from " + str); + LOGGER.log(new Status(Status.INFO, BUNDLE.getSymbolicName(), + "Create Quantity just with unit from " + str)); newNullableQuantity = new NullQuantity(dummy.getUnit()); } catch (final IllegalArgumentException ex1) { // Unit could not be parsed - LOGGER.log(Level.WARNING, "Unit '" + str + "' could not be parsed!", ex); + LOGGER.log(new Status(Status.WARNING, BUNDLE.getSymbolicName(), + "Unit '" + str + "' could not be parsed!", ex)); } } catch (final IllegalArgumentException ex) { // Quantity could not be parsed - LOGGER.log(Level.WARNING, "Quantity '" + str + "' could not be parsed!", ex); + LOGGER.log(new Status(Status.WARNING, BUNDLE.getSymbolicName(), + "Quantity '" + str + "' could not be parsed!", ex)); } return newNullableQuantity; } -- GitLab