2015-09-02 08:13:31 -05:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
|
|
)
|
|
|
|
|
2015-10-09 17:35:34 -05:00
|
|
|
// LogRoller implements a middleware that provides a rolling logger.
|
2015-09-02 08:13:31 -05:00
|
|
|
type LogRoller struct {
|
|
|
|
Filename string
|
|
|
|
MaxSize int
|
|
|
|
MaxAge int
|
|
|
|
MaxBackups int
|
|
|
|
LocalTime bool
|
|
|
|
}
|
|
|
|
|
2015-10-09 17:35:34 -05:00
|
|
|
// GetLogWriter returns an io.Writer that writes to a rolling logger.
|
2015-09-02 08:13:31 -05:00
|
|
|
func (l LogRoller) GetLogWriter() io.Writer {
|
|
|
|
return &lumberjack.Logger{
|
|
|
|
Filename: l.Filename,
|
|
|
|
MaxSize: l.MaxSize,
|
|
|
|
MaxAge: l.MaxAge,
|
|
|
|
MaxBackups: l.MaxBackups,
|
|
|
|
LocalTime: l.LocalTime,
|
|
|
|
}
|
|
|
|
}
|