1
0
Fork 0
mirror of https://github.com/Luzifer/gpxhydrant.git synced 2024-11-10 00:09:59 +00:00

Extracted debug logging to function

This commit is contained in:
Knut Ahlers 2016-05-07 15:00:58 +02:00
parent c59c4dfb79
commit 205dd8c4a7
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

30
main.go
View file

@ -50,6 +50,12 @@ func init() {
} }
} }
func logDebugf(format string, values ...interface{}) {
if cfg.Debug {
log.Printf(format, values...)
}
}
func main() { func main() {
gpsFile, err := os.Open(cfg.GPXFile) gpsFile, err := os.Open(cfg.GPXFile)
if err != nil { if err != nil {
@ -76,9 +82,7 @@ func main() {
} }
continue continue
} }
if cfg.Debug { logDebugf("Found a hydrant from waypoint %s: %#v", wp.Name, h)
log.Printf("Found a hydrant from waypoint %s: %#v", wp.Name, h)
}
hydrants = append(hydrants, h) hydrants = append(hydrants, h)
if minLat > h.Latitude { if minLat > h.Latitude {
@ -115,9 +119,7 @@ func main() {
} }
} }
if cfg.Debug { logDebugf("Working on Changeset %d", cs.ID)
log.Printf("Working on Changeset %d", cs.ID)
}
cs.Tags = []osm.Tag{ cs.Tags = []osm.Tag{
{Key: "comment", Value: cfg.Comment}, {Key: "comment", Value: cfg.Comment},
@ -134,9 +136,7 @@ func main() {
log.Fatalf("Unable to get map data: %s", err) log.Fatalf("Unable to get map data: %s", err)
} }
if cfg.Debug { logDebugf("Retrieved %d nodes from map", len(mapData.Nodes))
log.Printf("Retrieved %d nodes from map", len(mapData.Nodes))
}
availableHydrants := []*hydrant{} availableHydrants := []*hydrant{}
for _, n := range mapData.Nodes { for _, n := range mapData.Nodes {
@ -163,9 +163,7 @@ func main() {
log.Printf("[NOOP] Would send a create to OSM (Changeset %d): %#v", cs.ID, h.ToNode()) log.Printf("[NOOP] Would send a create to OSM (Changeset %d): %#v", cs.ID, h.ToNode())
} else { } else {
osmClient.SaveNode(h.ToNode(), cs) osmClient.SaveNode(h.ToNode(), cs)
if cfg.Debug { logDebugf("Created a hydrant: %s", h.Name)
log.Printf("Created a hydrant: %s", h.Name)
}
} }
continue continue
} }
@ -175,9 +173,7 @@ func main() {
} }
if h.Diameter == found.Diameter && h.Position == found.Position && h.Pressure == found.Pressure && h.Type == found.Type { if h.Diameter == found.Diameter && h.Position == found.Position && h.Pressure == found.Pressure && h.Type == found.Type {
if cfg.Debug { logDebugf("Found a good looking hydrant which needs no update: %#v", h)
log.Printf("Found a good looking hydrant which needs no update: %#v", h)
}
// Everything matches, we don't care // Everything matches, we don't care
continue continue
} }
@ -188,9 +184,7 @@ func main() {
log.Printf("[NOOP] Would send a change to OSM (Changeset %d): To=%#v From=%#v", cs.ID, h.ToNode(), found.ToNode()) log.Printf("[NOOP] Would send a change to OSM (Changeset %d): To=%#v From=%#v", cs.ID, h.ToNode(), found.ToNode())
} else { } else {
osmClient.SaveNode(h.ToNode(), cs) osmClient.SaveNode(h.ToNode(), cs)
if cfg.Debug { logDebugf("Changed a hydrant: %s", h.Name)
log.Printf("Changed a hydrant: %s", h.Name)
}
} }
} }
} }