diff --git a/rest/access_log_apache.go b/rest/access_log_apache.go index 72761f8..ebf5952 100644 --- a/rest/access_log_apache.go +++ b/rest/access_log_apache.go @@ -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. diff --git a/rest/access_log_json.go b/rest/access_log_json.go index a6bc175..3cca2db 100644 --- a/rest/access_log_json.go +++ b/rest/access_log_json.go @@ -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. diff --git a/rest/middleware.go b/rest/middleware.go index ba03fb8..7108f2e 100644 --- a/rest/middleware.go +++ b/rest/middleware.go @@ -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{}) +} diff --git a/rest/recover.go b/rest/recover.go index 99f1515..cac50fd 100644 --- a/rest/recover.go +++ b/rest/recover.go @@ -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