diff pkg/imports/sr.go @ 1138:443fc80a315f

Don't issue new lines at end of log messages when importing.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 09 Nov 2018 10:57:49 +0100
parents 2fb6c0a6ec8a
children 930fdd8b474f
line wrap: on
line diff
--- a/pkg/imports/sr.go	Thu Nov 08 16:30:53 2018 +0100
+++ b/pkg/imports/sr.go	Fri Nov 09 10:57:49 2018 +0100
@@ -24,7 +24,6 @@
 	"errors"
 	"fmt"
 	"io"
-	"log"
 	"os"
 	"path"
 	"path/filepath"
@@ -153,7 +152,7 @@
 	}
 	defer z.Close()
 
-	feedback.Info("Looking for 'meta.json'\n")
+	feedback.Info("Looking for 'meta.json'")
 	mf := find("meta.json", z.File)
 	if mf == nil {
 		return errors.New("Cannot find 'meta.json'")
@@ -168,7 +167,7 @@
 		return err
 	}
 
-	feedback.Info("Looking for '*.xyz'\n")
+	feedback.Info("Looking for '*.xyz'")
 	xyzf := find(".xyz", z.File)
 	if xyzf == nil {
 		return errors.New("Cannot find any *.xyz file")
@@ -210,17 +209,17 @@
 		m.EPSG,
 	).Scan(&id, &epsg)
 	xyz, polygon = nil, nil // not need from now on.
-	feedback.Info("storing points took %s\n", time.Since(start))
+	feedback.Info("storing points took %s", time.Since(start))
 	if err != nil {
 		return err
 	}
 
-	feedback.Info("Best suited UTM EPSG: %d\n", epsg)
+	feedback.Info("Best suited UTM EPSG: %d", epsg)
 
-	feedback.Info("Triangulate...\n")
+	feedback.Info("Triangulate...")
 	start = time.Now()
 	tin, err := octree.GenerateTinByID(conn, ctx, id, epsg)
-	feedback.Info("triangulation took %s\n", time.Since(start))
+	feedback.Info("triangulation took %s", time.Since(start))
 	if err != nil {
 		return err
 	}
@@ -229,24 +228,24 @@
 		return errors.New("cannot load TIN from database")
 	}
 
-	feedback.Info("Building octree...\n")
+	feedback.Info("Building octree...")
 	builder := octree.NewBuilder(tin)
 	start = time.Now()
 	builder.Build()
 	octreeIndex, err := builder.Bytes()
 	tin = nil // not needed from now on
-	feedback.Info("building octree took %s\n", time.Since(start))
+	feedback.Info("building octree took %s", time.Since(start))
 	if err != nil {
 		return err
 	}
 
-	feedback.Info("Store octree...\n")
+	feedback.Info("Store octree...")
 	start = time.Now()
 	h := sha1.New()
 	h.Write(octreeIndex)
 	checksum := hex.EncodeToString(h.Sum(nil))
 	_, err = tx.Exec(insertOctreeSQL, id, checksum, octreeIndex)
-	feedback.Info("storing octree index took %s\n", time.Since(start))
+	feedback.Info("storing octree index took %s", time.Since(start))
 	if err != nil {
 		return err
 	}
@@ -254,16 +253,18 @@
 	tree := builder.Tree()
 	builder = nil // not needed from now on
 
-	feedback.Info("Generate contour lines...\n")
+	feedback.Info("Generate contour lines...")
 	start = time.Now()
 	err = generateContours(tree, tx, id)
-	feedback.Info("generating and storing contour lines took %s\n", time.Since(start))
+	feedback.Info("generating and storing contour lines took %s", time.Since(start))
 	if err != nil {
 		return err
 	}
 
-	feedback.Info("Storing sounding result was successful.\n")
-	return tx.Commit()
+	if err = tx.Commit(); err == nil {
+		feedback.Info("Storing sounding result was successful.")
+	}
+	return err
 }
 
 func (srd *SoundingResultDate) UnmarshalJSON(data []byte) error {
@@ -348,26 +349,26 @@
 		// fmt.Sscanf(text, "%f,%f,%f") is 4 times slower.
 		idx := strings.IndexByte(text, ',')
 		if idx == -1 {
-			log.Printf("format error in line %d\n", line)
+			feedback.Warn("format error in line %d", line)
 			continue
 		}
 		var err error
 		if p.X, err = strconv.ParseFloat(text[:idx], 64); err != nil {
-			feedback.Warn("format error in line %d: %v\n", line, err)
+			feedback.Warn("format error in line %d: %v", line, err)
 			continue
 		}
 		text = text[idx+1:]
 		if idx = strings.IndexByte(text, ','); idx == -1 {
-			feedback.Warn("format error in line %d\n", line)
+			feedback.Warn("format error in line %d", line)
 			continue
 		}
 		if p.Y, err = strconv.ParseFloat(text[:idx], 64); err != nil {
-			feedback.Warn("format error in line %d: %v\n", line, err)
+			feedback.Warn("format error in line %d: %v", line, err)
 			continue
 		}
 		text = text[idx+1:]
 		if p.Z, err = strconv.ParseFloat(text, 64); err != nil {
-			feedback.Warn("format error in line %d: %v\n", line, err)
+			feedback.Warn("format error in line %d: %v", line, err)
 			continue
 		}
 		mpz = append(mpz, p)