2022-06-06 13:48:53 +00:00
|
|
|
package bootstrap
|
|
|
|
|
|
|
|
import (
|
2022-06-25 12:38:02 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
2022-06-14 09:18:58 +00:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2022-06-06 13:48:53 +00:00
|
|
|
"github.com/alist-org/alist/v3/cmd/args"
|
|
|
|
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
2022-06-06 14:06:33 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-06-06 13:48:53 +00:00
|
|
|
)
|
|
|
|
|
2022-06-14 09:18:58 +00:00
|
|
|
func init() {
|
2022-06-06 14:06:33 +00:00
|
|
|
logrus.SetFormatter(&logrus.TextFormatter{
|
2022-06-06 13:48:53 +00:00
|
|
|
ForceColors: true,
|
|
|
|
EnvironmentOverrideColors: true,
|
|
|
|
TimestampFormat: "2006-01-02 15:04:05",
|
|
|
|
FullTimestamp: true,
|
|
|
|
})
|
2022-06-14 09:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Log() {
|
|
|
|
log.SetOutput(logrus.StandardLogger().Out)
|
2022-06-25 13:34:44 +00:00
|
|
|
if args.Debug || args.Dev {
|
2022-06-14 09:18:58 +00:00
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
logrus.SetReportCaller(true)
|
|
|
|
}
|
2022-06-06 13:48:53 +00:00
|
|
|
logConfig := conf.Conf.Log
|
2022-06-09 07:12:34 +00:00
|
|
|
if logConfig.Enable {
|
2022-06-06 13:48:53 +00:00
|
|
|
var (
|
|
|
|
writer *rotatelogs.RotateLogs
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if logConfig.Name != "" {
|
|
|
|
writer, err = rotatelogs.New(
|
|
|
|
logConfig.Path,
|
|
|
|
rotatelogs.WithLinkName(logConfig.Name),
|
|
|
|
rotatelogs.WithRotationCount(logConfig.RotationCount),
|
|
|
|
rotatelogs.WithRotationTime(time.Duration(logConfig.RotationTime)*time.Hour),
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
writer, err = rotatelogs.New(
|
|
|
|
logConfig.Path,
|
|
|
|
rotatelogs.WithRotationCount(logConfig.RotationCount),
|
|
|
|
rotatelogs.WithRotationTime(time.Duration(logConfig.RotationTime)*time.Hour),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2022-06-06 14:06:33 +00:00
|
|
|
logrus.Fatalf("failed to create rotate logrus: %s", err)
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
2022-06-06 14:06:33 +00:00
|
|
|
logrus.SetOutput(writer)
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|
2022-06-06 14:06:33 +00:00
|
|
|
logrus.Infof("init logrus...")
|
2022-06-06 13:48:53 +00:00
|
|
|
}
|