Skip to content

Commit

Permalink
Use ForceFormatting to include prefix in file based logging (CMC-1497) (
Browse files Browse the repository at this point in the history
#138)

* improved clarity of conn deregistered on ones not fully authenticated
  • Loading branch information
itzg committed Apr 14, 2017
1 parent cac30bd commit b7fe38c
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
8 changes: 5 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import:
version: ^1.5.0
- package: github.com/fsnotify/fsnotify
version: ^1.4.2
- package: github.com/x-cray/logrus-prefixed-formatter
version: ~0.3.2
- package: github.com/racker/logrus-prefixed-formatter
version: force-formatter
- package: github.com/mgutz/ansi
- package: github.com/jpillora/backoff
- package: github.com/prometheus/client_golang
Expand Down
3 changes: 2 additions & 1 deletion poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"time"

log "github.com/Sirupsen/logrus"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
prefixed "github.com/racker/logrus-prefixed-formatter"

"github.com/racker/rackspace-monitoring-poller/commands"
"github.com/racker/rackspace-monitoring-poller/version"
Expand Down Expand Up @@ -82,6 +82,7 @@ func initEnv() {
} else {
log.SetFormatter(&prefixed.TextFormatter{
TimestampFormat: time.RFC1123,
ForceFormatting: true,
})
}
if globalFlags.LogfileName != "" {
Expand Down
4 changes: 4 additions & 0 deletions poller/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ func (conn *EleConnection) GetLogPrefix() string {
return conn.address
}

func (conn *EleConnection) String() string {
return conn.address
}

// Connect sets up a tcp connection with connection defined address
// and passed in tlsConfig
// If context is not set, ErrUndefinedContext is returned
Expand Down
30 changes: 19 additions & 11 deletions poller/connection_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,28 @@ func (cs *EleConnectionStream) registerConnection(qry string, conn Connection) {
}

func (cs *EleConnectionStream) deregisterConnection(qry string, conn Connection) {
hadConnections := len(cs.conns) > 0
delete(cs.conns, qry)
log.WithField("connections", cs.conns).
Debug("After deregistring, currently registered connections")
cs.EmitEvent(utils.NewEvent(EventTypeDeregister, conn))

if hadConnections && len(cs.conns) == 0 {
if _, exists := cs.conns[qry]; exists {
delete(cs.conns, qry)
log.WithFields(log.Fields{
"prefix": "scheduler",
}).Info("Lost all connections to endpoints")
"prefix": cs.GetLogPrefix(),
"connections": cs.conns,
}).Debug("After deregistering, currently registered connections")

cs.EmitEvent(utils.NewEvent(EventTypeDeregister, conn))
if len(cs.conns) == 0 {
log.WithFields(log.Fields{
"prefix": "scheduler",
}).Info("Lost all connections to endpoints")

for _, scheduler := range cs.schedulers {
scheduler.Reset()
for _, scheduler := range cs.schedulers {
scheduler.Reset()
}
}
} else {
log.WithFields(log.Fields{
"prefix": cs.GetLogPrefix(),
"connection": conn,
}).Debug("Saw deregistration, but connection wasn't fully ready.")
}
}

Expand Down

0 comments on commit b7fe38c

Please sign in to comment.