0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-23 22:27:38 -05:00
caddy/middleware/git/logger.go
2015-06-07 20:39:24 +01:00

38 lines
628 B
Go

package git
import (
"log"
"os"
"sync"
)
// logger is used to log errors
var logger = &gitLogger{l: log.New(os.Stderr, "", log.LstdFlags)}
// gitLogger wraps log.Logger with mutex for thread safety.
type gitLogger struct {
l *log.Logger
sync.RWMutex
}
func (g *gitLogger) logger() *log.Logger {
g.RLock()
defer g.RUnlock()
return g.l
}
func (g *gitLogger) setLogger(l *log.Logger) {
g.Lock()
g.l = l
g.Unlock()
}
// Logger gets the currently available logger
func Logger() *log.Logger {
return logger.logger()
}
// SetLogger sets the current logger to l
func SetLogger(l *log.Logger) {
logger.setLogger(l)
}