From dcee2c7e5e21461a70206bfb175a8feb1659dd10 Mon Sep 17 00:00:00 2001
From: Kai Brassel <mail@khbrassel.de>
Date: Thu, 10 Jun 2021 09:18:13 +0200
Subject: [PATCH] Log creation of Quantities

---
 .../cityunits/model/NullableQuantity.java           | 13 ++++++++-----
 1 file changed, 8 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 ae05702..5e26301 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
@@ -4,6 +4,8 @@ import java.text.NumberFormat;
 import java.text.ParseException;
 import java.util.Locale;
 import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.measure.Quantity;
 import javax.measure.Unit;
@@ -19,7 +21,8 @@ import tech.units.indriya.quantity.Quantities;
  * of the quantity is always defined.
  */
 public class NullableQuantity {
-
+	static Logger LOGGER = Logger.getLogger("de.hftstuttgart.cityunits");
+	
 	static {
 		// TODO Implement specific QuantityFormat to enable custom number format?
 		// ensure that editing, (de)serialization and default values of units all work
@@ -33,19 +36,19 @@ public class NullableQuantity {
 	public static NullableQuantity create(String str) {
 		NullableQuantity newNullableQuantity = null;
 		try {
+			LOGGER.log(Level.INFO, "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);
 				newNullableQuantity = new NullQuantity(dummy.getUnit());
 			} catch (final IllegalArgumentException ex1) { // Unit could not be parsed
-				System.out.println("Unit '" + str + "'  could not be parsed!"); //TODO
-				ex.printStackTrace();
+				LOGGER.log(Level.WARNING, "Unit '" + str + "'  could not be parsed!", ex);
 			}
 		} catch (final IllegalArgumentException ex) { // Quantity could not be parsed
-			System.out.println("Quantity '" + str + "' could not be parsed!");	//TODO
-			ex.printStackTrace();
+			LOGGER.log(Level.WARNING, "Quantity '" + str + "'  could not be parsed!", ex);
 		}
 		return newNullableQuantity;
 	}
-- 
GitLab