Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add logging interface for user specified loggers, such as logrus #185

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rest/access_log_apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type AccessLogApacheMiddleware struct {

// Logger points to the logger object used by this middleware, it defaults to
// log.New(os.Stderr, "", 0).
Logger *log.Logger
Logger Logger

// Format defines the format of the access log record. See AccessLogFormat for the details.
// It defaults to DefaultLogFormat.
Expand Down
2 changes: 1 addition & 1 deletion rest/access_log_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type AccessLogJsonMiddleware struct {

// Logger points to the logger object used by this middleware, it defaults to
// log.New(os.Stderr, "", 0).
Logger *log.Logger
Logger Logger
}

// MiddlewareFunc makes AccessLogJsonMiddleware implement the Middleware interface.
Expand Down
8 changes: 8 additions & 0 deletions rest/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,11 @@ func adapterFunc(handler HandlerFunc) http.HandlerFunc {
handler(writer, request)
}
}

// Logging interface which *log.Logger uses. Allows injection of user specified loggers.
type Logger interface {
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
Fatalf(format string, v ...interface{})
}
2 changes: 1 addition & 1 deletion rest/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type RecoverMiddleware struct {

// Custom logger used for logging the panic errors,
// optional, defaults to log.New(os.Stderr, "", 0)
Logger *log.Logger
Logger Logger

// If true, the log records will be printed as JSON. Convenient for log parsing.
EnableLogAsJson bool
Expand Down