File size: 1,334 Bytes
7107f0b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
package bootstrap
import (
"io"
"log"
"os"
"github.com/alist-org/alist/v3/cmd/flags"
"github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/pkg/utils"
"github.com/natefinch/lumberjack"
"github.com/sirupsen/logrus"
)
func init() {
formatter := logrus.TextFormatter{
ForceColors: true,
EnvironmentOverrideColors: true,
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
}
logrus.SetFormatter(&formatter)
utils.Log.SetFormatter(&formatter)
// logrus.SetLevel(logrus.DebugLevel)
}
func setLog(l *logrus.Logger) {
if flags.Debug || flags.Dev {
l.SetLevel(logrus.DebugLevel)
l.SetReportCaller(true)
} else {
l.SetLevel(logrus.InfoLevel)
l.SetReportCaller(false)
}
}
func Log() {
setLog(logrus.StandardLogger())
setLog(utils.Log)
logConfig := conf.Conf.Log
if logConfig.Enable {
var w io.Writer = &lumberjack.Logger{
Filename: logConfig.Name,
MaxSize: logConfig.MaxSize, // megabytes
MaxBackups: logConfig.MaxBackups,
MaxAge: logConfig.MaxAge, //days
Compress: logConfig.Compress, // disabled by default
}
if flags.Debug || flags.Dev || flags.LogStd {
w = io.MultiWriter(os.Stdout, w)
}
logrus.SetOutput(w)
}
log.SetOutput(logrus.StandardLogger().Out)
utils.Log.Infof("init logrus...")
}
|