|
|
@ -7,29 +7,30 @@ import (
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Logger interface
|
|
|
|
// Logger type
|
|
|
|
type Logger interface {
|
|
|
|
type Logger struct {
|
|
|
|
Println(v ...interface{})
|
|
|
|
logger *log.Logger
|
|
|
|
Printf(format string, v ...interface{})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LoggerHandler interface
|
|
|
|
// NewLogger returns a logger interface
|
|
|
|
type LoggerHandler interface {
|
|
|
|
func NewLogger() *Logger {
|
|
|
|
Logger
|
|
|
|
return &Logger{
|
|
|
|
ServeHTTP(http.ResponseWriter, *http.Request, http.HandlerFunc)
|
|
|
|
logger: log.New(os.Stdout, appLabel, log.Ldate|log.Lmicroseconds),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewLogger returns a logger interface
|
|
|
|
// Println is proxy for println
|
|
|
|
func NewLogger() LoggerHandler {
|
|
|
|
func (l *Logger) Println(v ...interface{}) {
|
|
|
|
return &logger{log.New(os.Stdout, appLabel, log.Ldate|log.Lmicroseconds)}
|
|
|
|
l.logger.Println(v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type logger struct {
|
|
|
|
// Printf calls Printf on logger
|
|
|
|
Logger
|
|
|
|
func (l *Logger) Printf(f string, v ...interface{}) {
|
|
|
|
|
|
|
|
l.logger.Printf(f, v...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
|
|
func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|
|
|
start := time.Now()
|
|
|
|
start := time.Now()
|
|
|
|
next(rw, r)
|
|
|
|
next(rw, r)
|
|
|
|
l.Printf("Completed %s to %s in %v", r.Method, r.URL.Path, time.Since(start))
|
|
|
|
l.logger.Printf("Completed %s to %s in %v", r.Method, r.URL.Path, time.Since(start))
|
|
|
|
}
|
|
|
|
}
|
|
|
|