func LoggerWithOption(options ...LoggerOption) func(http.Handler) http.Handler {
	mw := func(next http.Handler) http.Handler {
		fn := func(w http.ResponseWriter, r *http.Request) {
			var (
				ctx  = r.Context()
				meta = LoggerFields(r)
			)
			// prepare the logger
			logger := log.GetContext(ctx)
			// prepare the options
			options = append(options, LoggerOptionWithFields(meta))
			// compose the options
			for _, option := range options {
				logger = option.Apply(logger)
			}

			// overwrite the context
			ctx = log.SetContext(ctx, logger)

			var (
				writer = middleware.NewWrapResponseWriter(w, r.ProtoMajor)
				start  = time.Now()
			)

			next.ServeHTTP(writer, r.WithContext(ctx))

			logger = logger.WithFields(log.Map{
				"status":   writer.Status(),
				"size":     writer.BytesWritten(),
				"duration": time.Since(start),
			})

			switch {
			case writer.Status() >= 500:
				logger.Error("response completion fail")
			case writer.Status() >= 400:
				logger.Warn("response completion warn")
			default:
				logger.Info("response completion success")
			}
		}

		return http.HandlerFunc(fn)
	}

	return mw
}
// LoggerWithOption returns a logger middleware
LoggerWithOption returns a logger middleware
// LoggerWithOption returns a logger middleware
func LoggerWithOption(options ...LoggerOption) func(http.Handler) http.Handler {
	mw := func(next http.Handler) http.Handler {
		fn := func(w http.ResponseWriter, r *http.Request) {
			var (
				ctx  = r.Context()
				meta = LoggerFields(r)
			)
			logger := log.GetContext(ctx)
			options = append(options, LoggerOptionWithFields(meta))
			for _, option := range options {
				logger = option.Apply(logger)
			}
			ctx = log.SetContext(ctx, logger)
			var (
				writer = middleware.NewWrapResponseWriter(w, r.ProtoMajor)
				start  = time.Now()
			)
			next.ServeHTTP(writer, r.WithContext(ctx))
			logger = logger.WithFields(log.Map{
				"status":   writer.Status(),
				"size":     writer.BytesWritten(),
				"duration": time.Since(start),
			})
			switch {
			case writer.Status() >= 500:
				logger.Error("response completion fail")
			case writer.Status() >= 400:
				logger.Warn("response completion warn")
			default:
				logger.Info("response completion success")
			}
		}
		return http.HandlerFunc(fn)
	}
	return mw
}
func LoggerWithOption ( options ... LoggerOption ) func ( http . Handler ) http . Handler { mw := func ( next http . Handler ) http . Handler { fn := func ( w http . ResponseWriter , r * http . Request ) { var ( ctx = r . Context ( ) meta = LoggerFields ( r ) ) logger := log . GetContext ( ctx ) options = append ( options , LoggerOptionWithFields ( meta ) ) for _ , option := range options { logger = option . Apply ( logger ) } ctx = log . SetContext ( ctx , logger ) var ( writer = middleware . NewWrapResponseWriter ( w , r . ProtoMajor ) start = time . Now ( ) ) next . ServeHTTP ( writer , r . WithContext ( ctx ) ) logger = logger . WithFields ( log . Map { " " : writer . Status ( ) , " " : writer . BytesWritten ( ) , " " : time . Since ( start ) , } ) switch { case writer . Status ( ) >= 500 : logger . Error ( " " ) case writer . Status ( ) >= 400 : logger . Warn ( " " ) default : logger . Info ( " " ) } } return http . HandlerFunc ( fn ) } return mw }
LoggerWithOption returns a logger middleware
LoggerWithOption returns a logger middleware
// prepare the logger // prepare the options // compose the options // overwrite the context