Skip to content

RecoveryLogger should accept interface instead of struct! #92

@pavelnikolov

Description

@pavelnikolov

This code is not designed well: https://github.com/gorilla/handlers/blob/master/recovery.go#L49

func RecoveryLogger(logger *log.Logger) RecoveryOption {
	return func(h http.Handler) {
		r := h.(*recoveryHandler)
		r.logger = logger
	}
}

You should avoid accepting structs and instead try to accept interfaces whenever possible. In this particular case, since you are only using the Println(...interface{}) method, you should create an interface for the input argument like this:

type Logger interface {
    Println(v ...interface{}}
}

This would allow users to pass a custom structured logger (e.g. Logrus), which might have some other fields/tags like environment, host, user, application etc. Unstructured logs in a highly distributed environment are totally useless.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions