Skip to content

Commit

Permalink
minor improvements to logging (#175)
Browse files Browse the repository at this point in the history
* minor improvements to logging

* chore(*): change log.Infoln to log.Info

* fix: fix incorrect example code
  • Loading branch information
Yerken authored and linki committed Apr 26, 2017
1 parent d4a396b commit 82a172a
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Controller) Run(stopChan <-chan struct{}) {
select {
case <-time.After(c.Interval):
case <-stopChan:
log.Infoln("Terminating main controller loop")
log.Info("Terminating main controller loop")
return
}
}
Expand Down
2 changes: 1 addition & 1 deletion endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ func (e *Endpoint) MergeLabels(labels map[string]string) {
}

func (e *Endpoint) String() string {
return fmt.Sprintf("%s: %s -> %s", e.RecordType, e.DNSName, e.Target)
return fmt.Sprintf(`%s -> %s (type "%s")`, e.DNSName, e.Target, e.RecordType)
}
10 changes: 5 additions & 5 deletions internal/testutils/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ func ExampleSameEndpoints() {
fmt.Println(ep)
}
// Output:
// A: abc.com -> 1.2.3.4
// TXT: abc.com -> something
// CNAME: bbc.com -> foo.com
// : example.org -> load-balancer.org
// TXT: example.org -> load-balancer.org
// abc.com -> 1.2.3.4 (type "A")
// abc.com -> something (type "TXT")
// bbc.com -> foo.com (type "CNAME")
// example.org -> load-balancer.org (type "")
// example.org -> load-balancer.org (type "TXT")
}
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func main() {

ctrl.Run(stopChan)
for {
log.Infoln("pod waiting to be deleted")
log.Info("Pod waiting to be deleted")
time.Sleep(time.Second * 30)
}
}
Expand All @@ -162,7 +162,7 @@ func handleSigterm(stopChan chan struct{}) {
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGTERM)
<-signals
log.Infoln("received SIGTERM. Terminating...")
log.Info("Received SIGTERM. Terminating...")
close(stopChan)
}

Expand Down
8 changes: 5 additions & 3 deletions provider/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (p *AWSProvider) ApplyChanges(_ string, changes *plan.Changes) error {
func (p *AWSProvider) submitChanges(changes []*route53.Change) error {
// return early if there is nothing to change
if len(changes) == 0 {
log.Info("All records are already up to date")
return nil
}

Expand All @@ -201,7 +202,7 @@ func (p *AWSProvider) submitChanges(changes []*route53.Change) error {

for z, cs := range changesByZone {
for _, c := range cs {
log.Infof("Changing records: %s %s", aws.StringValue(c.Action), c.String())
log.Infof("Changing records: %s %s ...", aws.StringValue(c.Action), c.String())
}
if !p.DryRun {
params := &route53.ChangeResourceRecordSetsInput{
Expand All @@ -212,8 +213,10 @@ func (p *AWSProvider) submitChanges(changes []*route53.Change) error {
}

if _, err := p.Client.ChangeResourceRecordSets(params); err != nil {
log.Error(err)
log.Error(err) //TODO(ideahitme): consider changing the interface in cases when this error might be a concern for other components
continue
}
log.Infof("Record in zone %s were successfully updated", aws.StringValue(zones[z].Name))
}
}

Expand Down Expand Up @@ -242,7 +245,6 @@ func changesByZone(zones map[string]*route53.HostedZone, changeSet []*route53.Ch
// separating a change could lead to empty sub changes, remove them here.
for zone, change := range changes {
if len(change) == 0 {
log.Infof("No records to be changed in zone: %s", aws.StringValue(zones[zone].Name))
delete(changes, zone)
}
}
Expand Down
2 changes: 1 addition & 1 deletion provider/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (p *googleProvider) ApplyChanges(_ string, changes *plan.Changes) error {
// submitChange takes a zone and a Change and sends it to Google.
func (p *googleProvider) submitChange(change *dns.Change) error {
if len(change.Additions) == 0 && len(change.Deletions) == 0 {
log.Infoln("Received empty list of records for creation and deletion")
log.Info("All records are already up to date")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func filterOwnedRecords(ownerID string, eps []*endpoint.Endpoint) []*endpoint.En
filtered := []*endpoint.Endpoint{}
for _, ep := range eps {
if endpointOwner, ok := ep.Labels[endpoint.OwnerLabelKey]; !ok || endpointOwner != ownerID {
log.Debugf("Skipping endpoint %v because owner id does not match, found: %s, required: %s", ep, endpointOwner, ownerID)
log.Debugf(`Skipping endpoint %v because owner id does not match, found: "%s", required: "%s"`, ep, endpointOwner, ownerID)
continue
}
filtered = append(filtered, ep)
Expand Down

0 comments on commit 82a172a

Please sign in to comment.