|
|
|
@ -7,29 +7,30 @@ import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Logger interface
|
|
|
|
|
type Logger interface {
|
|
|
|
|
Println(v ...interface{})
|
|
|
|
|
Printf(format string, v ...interface{})
|
|
|
|
|
// Logger type
|
|
|
|
|
type Logger struct {
|
|
|
|
|
logger *log.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LoggerHandler interface
|
|
|
|
|
type LoggerHandler interface {
|
|
|
|
|
Logger
|
|
|
|
|
ServeHTTP(http.ResponseWriter, *http.Request, http.HandlerFunc)
|
|
|
|
|
// NewLogger returns a logger interface
|
|
|
|
|
func NewLogger() *Logger {
|
|
|
|
|
return &Logger{
|
|
|
|
|
logger: log.New(os.Stdout, appLabel, log.Ldate|log.Lmicroseconds),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewLogger returns a logger interface
|
|
|
|
|
func NewLogger() LoggerHandler {
|
|
|
|
|
return &logger{log.New(os.Stdout, appLabel, log.Ldate|log.Lmicroseconds)}
|
|
|
|
|
// Println is proxy for println
|
|
|
|
|
func (l *Logger) Println(v ...interface{}) {
|
|
|
|
|
l.logger.Println(v...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type logger struct {
|
|
|
|
|
Logger
|
|
|
|
|
// Printf calls Printf on 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()
|
|
|
|
|
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))
|
|
|
|
|
}
|
|
|
|
|