func (l *Logger) Sync() {
	l.logger.Sync()
}
Sync flushes any buffered log entries.
package util
import (
	"context"
	"net/http"
	"time"
	"github.com/pkg/errors"
	"go.uber.org/zap"
)
type Logger struct {
	logger *zap.SugaredLogger
}
func NewLogger(level, serviceName string) (*Logger, error) {
	atom := zap.NewAtomicLevel()
	switch level {
	case "debug":
		atom.SetLevel(zap.DebugLevel)
	case "warn":
		atom.SetLevel(zap.WarnLevel)
	case "error":
		atom.SetLevel(zap.ErrorLevel)
	default:
		level = "info"
		atom.SetLevel(zap.InfoLevel)
	}
	cfg := zap.Config{
		Development:       false,
		DisableCaller:     true,
		DisableStacktrace: false,
		EncoderConfig:     zap.NewProductionEncoderConfig(),
		Encoding:          "json",
		ErrorOutputPaths:  []string{"stdout"},
		Level:             atom,
		OutputPaths:       []string{"stdout"},
	}
	if cfg.InitialFields == nil {
		cfg.InitialFields = make(map[string]interface{})
	}
	cfg.InitialFields["service"] = serviceName
	l, err := cfg.Build()
	if err != nil {
		return nil, errors.Wrap(err, "Unable to initialize zap Logger")
	}
	l.Debug("Logger created",
		zap.String("level", level),
	)
	return &Logger{logger: l.Sugar()}, nil
}
func LoggerMiddleware(inner http.Handler, logger *Logger) http.HandlerFunc {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		start := time.Now()
		log := RequestIDLogger(logger, r)
		log.Debugw("request received",
			"address", r.RemoteAddr,
			"method", r.Method,
			"path", r.RequestURI,
		)
		inner.ServeHTTP(w, r)
		log.Infow("request completed",
			"address", r.RemoteAddr,
			"method", r.Method,
			"path", r.RequestURI,
			"duration", time.Since(start),
		)
	})
}
func RequestIDLogger(l *Logger, r *http.Request) *Logger {
	reqID := RequestIDFromContext(r.Context())
	log := l.logger.With("requestID", reqID)
	return &Logger{log}
}
func RequestIDLoggerFromContext(ctx context.Context, l *Logger) *Logger {
	reqID := RequestIDFromContext(ctx)
	log := l.logger.With("requestID", reqID)
	return &Logger{log}
}
func (l *Logger) Info(args ...interface{}) {
	l.logger.Info(args...)
}
func (l *Logger) Infof(msg string, args ...interface{}) {
	l.logger.Infof(msg, args...)
}
func (l *Logger) Infow(msg string, kv ...interface{}) {
	l.logger.Infow(msg, kv...)
}
func (l *Logger) Error(msg string) {
	l.logger.Error(msg)
}
func (l *Logger) Errorw(msg string, kv ...interface{}) {
	l.logger.Errorw(msg, kv...)
}
func (l *Logger) Warn(args ...interface{}) {
	l.logger.Warn(args...)
}
func (l *Logger) Warnf(msg string, args ...interface{}) {
	l.logger.Warnf(msg, args...)
}
func (l *Logger) Warnw(msg string, kv ...interface{}) {
	l.logger.Warnw(msg, kv...)
}
func (l *Logger) Debug(args ...interface{}) {
	l.logger.Debug(args...)
}
func (l *Logger) Debugf(msg string, args ...interface{}) {
	l.logger.Debugf(msg, args...)
}
func (l *Logger) Debugw(msg string, kv ...interface{}) {
	l.logger.Debugw(msg, kv...)
}
func (l *Logger) Panic(args ...interface{}) {
	l.logger.Panic(args...)
}
func (l *Logger) Panicf(msg string, args ...interface{}) {
	l.logger.Panicf(msg, args...)
}
func (l *Logger) Panicw(msg string, kv ...interface{}) {
	l.logger.Panicw(msg, kv...)
}
func (l *Logger) Fatal(args ...interface{}) {
	l.logger.Fatal(args...)
}
func (l *Logger) Fatalf(msg string, args ...interface{}) {
	l.logger.Fatalf(msg, args...)
}
func (l *Logger) Fatalw(msg string, kv ...interface{}) {
	l.logger.Fatalw(msg, kv...)
}