Add WithVersion to context and other cleanup

By adding WithVersion to the context package, we can simplify context setup in
the application. This avoids some odd bugs where instantiation order can lead
to missing instance.id or version from log messages.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2015-09-10 20:41:58 -07:00
parent 360c24d975
commit 530afa5234
6 changed files with 62 additions and 11 deletions

View file

@ -90,8 +90,16 @@ func getLogrusLogger(ctx Context, keys ...interface{}) *logrus.Entry {
}
if logger == nil {
fields := logrus.Fields{}
// Fill in the instance id, if we have it.
instanceID := ctx.Value("instance.id")
if instanceID != nil {
fields["instance.id"] = instanceID
}
// If no logger is found, just return the standard logger.
logger = logrus.NewEntry(logrus.StandardLogger())
logger = logrus.StandardLogger().WithFields(fields)
}
fields := logrus.Fields{}