Commit d55dd16b authored by Brian Tiger Chow's avatar Brian Tiger Chow

feat(elog) Option

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent 395f8a6e
package elog
import (
"io"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/Sirupsen/logrus"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/gopkg.in/natefinch/lumberjack.v2"
)
type Option func()
func SetOption(o Option) {
o()
}
var JSONFormatter = func() {
logrus.SetFormatter(&logrus.JSONFormatter{})
}
var TextFormatter = func() {
logrus.SetFormatter(&logrus.TextFormatter{})
}
type LogRotatorConfig struct {
File string
MaxSizeMB uint64
MaxBackups uint64
MaxAgeDays uint64
}
func Output(w io.Writer) Option {
return func() {
logrus.SetOutput(w)
// TODO return previous Output option
}
}
func OutputRotatingLogFile(config LogRotatorConfig) Option {
return func() {
logrus.SetOutput(
&lumberjack.Logger{
Filename: config.File,
MaxSize: int(config.MaxSizeMB),
MaxBackups: int(config.MaxBackups),
MaxAge: int(config.MaxAgeDays),
})
}
}
// TODO log levels? logrus.SetLevel(logrus.DebugLevel)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment