 5cab90d270
			
		
	
	5cab90d270
	
	
	
		
			
			After comtemplation, the complexity of the logging module system outweighs its usefulness. This changeset removes the system and restores lighter weight code paths. As a concession, we can always provide more context when necessary to log messages to understand them without having to fork the context for a certain set of calls. Signed-off-by: Stephen J Day <stephen.day@docker.com>
		
			
				
	
	
		
			41 lines
		
	
	
		
			880 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			880 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package log
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 
 | |
| 	"github.com/sirupsen/logrus"
 | |
| )
 | |
| 
 | |
| var (
 | |
| 	// G is an alias for GetLogger.
 | |
| 	//
 | |
| 	// We may want to define this locally to a package to get package tagged log
 | |
| 	// messages.
 | |
| 	G = GetLogger
 | |
| 
 | |
| 	// L is an alias for the the standard logger.
 | |
| 	L = logrus.NewEntry(logrus.StandardLogger())
 | |
| )
 | |
| 
 | |
| type (
 | |
| 	loggerKey struct{}
 | |
| )
 | |
| 
 | |
| // WithLogger returns a new context with the provided logger. Use in
 | |
| // combination with logger.WithField(s) for great effect.
 | |
| func WithLogger(ctx context.Context, logger *logrus.Entry) context.Context {
 | |
| 	return context.WithValue(ctx, loggerKey{}, logger)
 | |
| }
 | |
| 
 | |
| // GetLogger retrieves the current logger from the context. If no logger is
 | |
| // available, the default logger is returned.
 | |
| func GetLogger(ctx context.Context) *logrus.Entry {
 | |
| 	logger := ctx.Value(loggerKey{})
 | |
| 
 | |
| 	if logger == nil {
 | |
| 		return L
 | |
| 	}
 | |
| 
 | |
| 	return logger.(*logrus.Entry)
 | |
| }
 |