Skip to content

Commit

Permalink
Update logging format to align messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Claes Mogren committed May 16, 2019
1 parent b9c8f98 commit ccf1c29
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cni-metrics-helper/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func postProcessingHistogram(convert metricsConvert) bool {
for _, action := range convert.actions {
numOfBuckets := len(action.bucket.curBucket)
if numOfBuckets == 0 {
glog.Info(" Post Histogram Processing: no bucket found")
glog.Info("Post Histogram Processing: no bucket found")
continue
}
for i := 1; i < numOfBuckets; i++ {
Expand Down
2 changes: 1 addition & 1 deletion ipamd/introspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type LoggingHandler struct {
}

func (lh LoggingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Info("Handling http request: ", ", method: ", r.Method, ", from: ", r.RemoteAddr, ", URI: ", r.RequestURI)
log.Infof("Handling http request: %s, from: %s, URI: %s", r.Method, r.RemoteAddr, r.RequestURI)
lh.h.ServeHTTP(w, r)
}

Expand Down
8 changes: 4 additions & 4 deletions ipamd/ipamd.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (c *IPAMContext) nodeInit() error {
_, _, err = c.dataStore.AssignPodIPv4Address(ip)
if err != nil {
ipamdErrInc("nodeInitAssignPodIPv4AddressFailed", err)
log.Warnf("During ipamd init, failed to use pod ip %s returned from Kubelet %v", ip.IP, err)
log.Warnf("During ipamd init, failed to use pod IP %s returned from Kubelet %v", ip.IP, err)
// TODO continue, but need to add node health stats here
// TODO need to feed this to controller on the health of pod and node
// This is a bug among kubelet/cni-plugin/l-ipamd/ec2-metadata that this particular pod is using an non existent ip address.
Expand Down Expand Up @@ -452,7 +452,7 @@ func (c *IPAMContext) decreaseIPPool(interval time.Duration) {
logPoolStats(total, used, c.currentMaxAddrsPerENI, c.maxAddrsPerENI)
}

// tryFreeENI always trys to free one ENI
// tryFreeENI always tries to free one ENI
func (c *IPAMContext) tryFreeENI() {
warmIPTarget := getWarmIPTarget()

Expand Down Expand Up @@ -637,7 +637,7 @@ func (c *IPAMContext) tryAllocateENI() {

maxIPPerENI, err := c.awsClient.GetENIipLimit()
if err != nil {
log.Infof("Failed to retrieve ENI IP limit: %v", err)
log.Warnf("Failed to retrieve ENI IP limit: %v", err)
return
}

Expand Down Expand Up @@ -1009,7 +1009,7 @@ func (c *IPAMContext) eniIPPoolReconcile(ipPool map[string]*datastore.AddressInf
if isReallyAttachedToENI {
c.reconcileCooldownCache.Remove(localIP)
} else {
log.Warnf(" Skipping IP %s on ENI %s because it does not belong to this ENI!.", localIP, eni)
log.Warnf("Skipping IP %s on ENI %s because it does not belong to this ENI!.", localIP, eni)
continue
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/eniconfig/eniconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (h *Handler) Handle(ctx context.Context, event sdk.Event) error {
h.controller.eniLock.Lock()
defer h.controller.eniLock.Unlock()
h.controller.myENI = val
log.Infof(" Setting myENI to: %s", val)
log.Infof("Setting myENI to: %s", val)
}
}
return nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/k8sapi/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (d *Controller) handlePodUpdate(key string) error {
}

if !exists {
log.Infof(" Pods deleted on my node: %v", key)
log.Infof("Pods deleted on my node: %v", key)
d.workerPodsLock.Lock()
defer d.workerPodsLock.Unlock()
delete(d.workerPods, key)
Expand Down Expand Up @@ -253,12 +253,12 @@ func (d *Controller) handlePodUpdate(key string) error {
IP: pod.Status.PodIP,
}

log.Infof(" Add/Update for Pod %s on my node, namespace = %s, IP = %s", podName, d.workerPods[key].Namespace, d.workerPods[key].IP)
log.Infof("Add/Update for Pod %s on my node, namespace = %s, IP = %s", podName, d.workerPods[key].Namespace, d.workerPods[key].IP)
} else if strings.HasPrefix(key, metav1.NamespaceSystem+"/"+cniPodName) {
d.cniPodsLock.Lock()
defer d.cniPodsLock.Unlock()

log.Infof(" Add/Update for CNI pod %s", podName)
log.Infof("Add/Update for CNI pod %s", podName)
d.cniPods[podName] = podName
}
return nil
Expand Down
10 changes: 6 additions & 4 deletions pkg/utils/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
%s
</outputs>
<formats>
<format id="main" format="%%UTCDate(2006-01-02T15:04:05Z07:00) [%%LEVEL] %%Msg%%n" />
<format id="main" format="%%UTCDate(2006-01-02T15:04:05Z07:00) [%%LEVEL]%%t%%Msg%%n" />
</formats>
</seelog>
`
Expand All @@ -46,7 +46,6 @@ func GetLogFileLocation(defaultLogFilePath string) string {
if logFilePath == "" {
logFilePath = defaultLogFilePath
}

return logFilePath
}

Expand All @@ -57,15 +56,18 @@ func SetupLogger(logFilePath string) {
fmt.Println("Error setting up logger: ", err)
return
}
log.ReplaceLogger(logger)
err = log.ReplaceLogger(logger)
if err != nil {
fmt.Println("Error replacing logger: ", err)
return
}
}

func getLogLevel() string {
seelogLevel, ok := log.LogLevelFromString(strings.ToLower(os.Getenv(envLogLevel)))
if !ok {
seelogLevel = log.InfoLvl
}

return seelogLevel.String()
}

Expand Down

0 comments on commit ccf1c29

Please sign in to comment.