// New creates and returns a new request logger middleware.
// Do not confuse it with the framework's Logger.
// This is for the http requests.
//
// Receives an optional configuation.
968234
func New(cfg ...Config) context.Handler {
	c := DefaultConfig()
	if len(cfg) > 0 {
		c = cfg[0]
	}
	c.buildSkipper()
	l := &requestLoggerMiddleware{config: c}

	return l.ServeHTTP
}
1174990
func New() *Logger {
	defaultOutputMutex.RLock()
	defer defaultOutputMutex.RUnlock()

	logger := &Logger{
		Fields:  make(map[string]interface{}),
		outputs: make([]*loggerOutputWrapper, len(defaultOutputs)),
	}
	copy(logger.outputs, defaultOutputs)

	return logger
}
513552
func New(handler Handler, flag int) *Logger {
	var l = new(Logger)

	l.level = LevelInfo
	l.handler = handler

	l.flag = flag

	l.quit = make(chan struct{})
	l.closed = false

	l.msg = make(chan []byte, 1024)

	l.bufs = make([][]byte, 0, 16)

	l.wg.Add(1)
	go l.run()

	return l
}
126373
func New(info logger.Info) (logger.Logger, error) {
	tag, err := loggerutils.ParseLogTag(info, loggerutils.DefaultTemplate)
	if err != nil {
		return nil, err
	}

	proto, address, err := parseAddress(info.Config["syslog-address"])
	if err != nil {
		return nil, err
	}

	facility, err := parseFacility(info.Config["syslog-facility"])
	if err != nil {
		return nil, err
	}

	syslogFormatter, syslogFramer, err := parseLogFormat(info.Config["syslog-format"], proto)
	if err != nil {
		return nil, err
	}

	var log *syslog.Writer
	if proto == secureProto {
		tlsConfig, tlsErr := parseTLSConfig(info.Config)
		if tlsErr != nil {
			return nil, tlsErr
		}
		log, err = syslog.DialWithTLSConfig(proto, address, facility, tag, tlsConfig)
	} else {
		log, err = syslog.Dial(proto, address, facility, tag)
	}

	if err != nil {
		return nil, err
	}

	log.SetFormatter(syslogFormatter)
	log.SetFramer(syslogFramer)

	return &syslogger{
		writer: log,
	}, nil
}
724522
func New(opts *Options) func(h http.Handler) http.Handler {
	if opts == nil || opts.Log == nil {
		opts = &Options{Log: log.Print}
	}

	return func(h http.Handler) http.Handler {
		fn := func(w http.ResponseWriter, r *http.Request) {
			defer func() {
				if err := recover(); err != nil {
					frames := stack.Callers(3)

					opts.Log(fmt.Sprintf(logFmt, titleClr("PANIC"), err, frames.String()))

					w.WriteHeader(http.StatusInternalServerError)

					ct := r.Header.Get(contentType)
					if strings.HasPrefix(ct, applicationJSON) {
						w.Header().Set(contentType, applicationJSONCharsetUTF8)

						e := jsonError{Message: err, Location: frames[0].String()}
						json.NewEncoder(w).Encode(e)
					} else {
						w.Write(compileTemplate(r, err, frames))
					}
				}
			}()
			h.ServeHTTP(w, r)
		}
		return http.HandlerFunc(fn)
	}
}
802698
func New(handler http.Handler) *CSRFHandler {
	baseCookie := http.Cookie{}
	baseCookie.MaxAge = MaxAge

	csrf := &CSRFHandler{successHandler: handler,
		failureHandler: http.HandlerFunc(defaultFailureHandler),
		baseCookie:     baseCookie,
	}

	return csrf
}
58776
func New(l *log.Logger, ll Level) Logger {
	return &logger{
		Logger:   l,
		Level:    ll,
		ctxPairs: []interface{}{},
	}
}
734773
func New(logger log.Logger, ints, chars metrics.Counter) Service {
	var svc Service
	{
		svc = NewBasicService()
		svc = LoggingMiddleware(logger)(svc)
		svc = InstrumentingMiddleware(ints, chars)(svc)
	}
	return svc
}
915081
func New(format string) (*ApacheLog, error) {
	var f Format
	if err := f.compile(format); err != nil {
		return nil, errors.Wrap(err, "failed to compile log format")
	}

	return &ApacheLog{format: &f}, nil
}
531740
func New(info logger.Info) (logger.Logger, error) {
	logrus.WithField("container", info.ContainerID).
		WithField("token", info.Config[token]).
		WithField("line-only", info.Config[lineonly]).
		Debug("logging driver logentries configured")

	log, err := le_go.Connect(info.Config[token])
	if err != nil {
		return nil, errors.Wrap(err, "error connecting to logentries")
	}
	var lineOnly bool
	if info.Config[lineonly] != "" {
		if lineOnly, err = strconv.ParseBool(info.Config[lineonly]); err != nil {
			return nil, errors.Wrap(err, "error parsing lineonly option")
		}
	}
	return &logentries{
		containerID:   info.ContainerID,
		containerName: info.ContainerName,
		writer:        log,
		lineOnly:      lineOnly,
	}, nil
}
1035162
func New(ctx context.Context, next http.Handler, config config.AddPrefix, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
	var result *addPrefix

	if len(config.Prefix) > 0 {
		result = &addPrefix{
			prefix: config.Prefix,
			next:   next,
			name:   name,
		}
	} else {
		return nil, fmt.Errorf("prefix cannot be empty")
	}

	return result, nil
}
779618
func New(name string) Logger {
	l := Logger(&logger{
		level:       levels.DEBUG,
		name:        name,
		enabled:     make(map[levels.LogLevel]bool),
		appender:    appenders.Console(),
		children:    make([]Logger, 0),
		parent:      nil,
		ExitOnFatal: true,
	})
	l.SetLevel(levels.DEBUG)
	return l
}
833204
func New() *Logger {
	return &Logger{
		Level:  InfoLevel,
		Logger: log.New(os.Stderr, "", 0),
	}
}
1114464
func New(c *Options) (s *Server) {
	c.ensure()
	s = &Server{
		cfg:    c,
		Logger: log.Get(PkgName),
		Binder: new(binder),
		router: router.New(router.Options{}),
		routes: make(map[string]router.Route),
	}
	s.stdLogger = slog.New(s.Logger, "web > ", 0)
	s.ctxPool = newContextPool(s)
	return s
}
212051
func New(cfg *Config) (*Server, error) {
	// pull a few parameters from the configuration passed in by snapteld
	s := &Server{
		err:        make(chan error),
		killChan:   make(chan struct{}),
		addrString: cfg.Address,
		pprof:      cfg.Pprof,
	}
	if cfg.HTTPS {
		var err error
		s.snapTLS, err = newtls(cfg.RestCertificate, cfg.RestKey)
		if err != nil {
			return nil, err
		}
		protocolPrefix = "https"
	}
	restLogger.Info(fmt.Sprintf("Configuring REST API with HTTPS set to: %v", cfg.HTTPS))

	s.apis = []api.API{
		v1.New(&s.wg, s.killChan, protocolPrefix),
		v2.New(&s.wg, s.killChan, protocolPrefix),
	}

	s.n = negroni.New(
		NewLogger(),
		negroni.NewRecovery(),
		negroni.HandlerFunc(s.authMiddleware),
	)
	s.r = httprouter.New()

	// CORS has to be turned on explicitly in the global config.
	// Otherwise, it defauts to the same origin.
	origins, err := s.getAllowedOrigins(cfg.Corsd)
	if err != nil {
		return nil, err
	}
	if len(origins) > 0 {
		c := cors.New(cors.Options{
			AllowedOrigins: origins,
			AllowedMethods: []string{allowedMethods},
			AllowedHeaders: []string{allowedHeaders},
			MaxAge:         maxAge,
		})
		s.n.Use(c)
	}

	// Use negroni to handle routes
	s.n.UseHandler(s.r)
	return s, nil
}
694639
func New(ctx context.Context, next http.Handler, config config.ErrorPage, serviceBuilder serviceBuilder, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	httpCodeRanges, err := types.NewHTTPCodeRanges(config.Status)
	if err != nil {
		return nil, err
	}

	backend, err := serviceBuilder.BuildHTTP(ctx, config.Service, nil)
	if err != nil {
		return nil, err
	}

	return &customErrors{
		name:           name,
		next:           next,
		backendHandler: backend,
		httpCodeRanges: httpCodeRanges,
		backendQuery:   config.Query,
	}, nil
}
994947
func New(w io.Writer, prefix string, flag int) *log.Logger {
	return log.New(NewWriter(w), prefix, flag)
}